Browse Source

Store XAML in embedded resources.

Instead of "Build Action: Resource" as xbuild on mono doesn't support
this. We may change back later if we can get it supported.
pull/148/head
Steven Kirk 11 years ago
parent
commit
6b19582945
  1. 4
      samples/XamlTestApplication/XamlTestApplication.csproj
  2. 17
      src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs
  3. 17
      src/Windows/Perspex.Win32/AssetLoader.cs

4
samples/XamlTestApplication/XamlTestApplication.csproj

@ -157,9 +157,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<Resource Include="Views\MainWindow.xaml"> <EmbeddedResource Include="Views\MainWindow.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Resource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\src\Shared\perspex.platform.targets" /> <Import Project="..\..\src\Shared\perspex.platform.targets" />

17
src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs

@ -111,20 +111,11 @@ namespace Perspex.Markup.Xaml
/// <returns>The URI.</returns> /// <returns>The URI.</returns>
private static IEnumerable<Uri> GetUrisFor(Type type) private static IEnumerable<Uri> GetUrisFor(Type type)
{ {
if (type.Namespace != null) return new[]
{ {
var toRemove = type.GetTypeInfo().Assembly.GetName().Name; new Uri(type.FullName + ".xaml", UriKind.Relative),
var substracted = toRemove.Length < type.Namespace.Length ? type.Namespace.Remove(0, toRemove.Length + 1) : ""; new Uri(type.FullName + ".paml", UriKind.Relative),
var replace = substracted.Replace('.', '/'); };
if (replace != string.Empty)
{
replace = replace + "/";
}
foreach (var ext in new[] {".xaml", ".paml"})
yield return new Uri(replace + type.Name + ext, UriKind.Relative);
}
} }
} }
} }

17
src/Windows/Perspex.Win32/AssetLoader.cs

@ -26,20 +26,7 @@ namespace Perspex.Win32
public Stream Open(Uri uri) public Stream Open(Uri uri)
{ {
var assembly = Assembly.GetEntryAssembly(); var assembly = Assembly.GetEntryAssembly();
var resourceName = assembly.GetName().Name + ".g"; return assembly.GetManifestResourceStream(uri.ToString());
var manager = new ResourceManager(resourceName, assembly);
using (var resourceSet = manager.GetResourceSet(CultureInfo.CurrentCulture, true, true))
{
var stream = (Stream)resourceSet.GetObject(uri.ToString(), true);
if (stream == null)
{
throw new FileNotFoundException($"The requested asset could not be found: {uri}");
}
return stream;
}
} }
} }
} }
Loading…
Cancel
Save