Guest User

Untitled

a guest
Jun 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public static ResourceDictionary GetAppResourceDictionary()
  2. {
  3. var assembly = Assembly.GetExecutingAssembly();
  4. string resourceDictionaryXaml;
  5. using (var appXamlResource = assembly.GetManifestResourceStream("Your.Namespace.Here.App.xaml"))
  6. {
  7. var appXamlBytes = new byte[appXamlResource.Length];
  8. appXamlResource.Read(appXamlBytes, 0, appXamlBytes.Length);
  9. var appXaml = Encoding.UTF8.GetString(appXamlBytes);
  10. resourceDictionaryXaml = appXaml.Replace("<Application.Resources>", string.Empty);
  11. resourceDictionaryXaml = resourceDictionaryXaml.Replace("</Application.Resources>", string.Empty);
  12. resourceDictionaryXaml = resourceDictionaryXaml.Replace("Application", "ResourceDictionary");
  13. resourceDictionaryXaml = resourceDictionaryXaml.Replace(
  14. "\"clr-namespace:Your.Namespace.Here\"",
  15. "\"clr-namespace:Your.Namespace.Here;assembly=YourAssembly\"");
  16. var xClassAttribute = string.Format("x:Class=\"{0}\"", (typeof(App)).FullName);
  17. resourceDictionaryXaml = resourceDictionaryXaml.Replace(xClassAttribute, string.Empty);
  18. var resourceDictionaryXamlBytes = Encoding.UTF8.GetBytes(resourceDictionaryXaml);
  19. using (var ms = new MemoryStream(resourceDictionaryXamlBytes))
  20. {
  21. return (ResourceDictionary)XamlReader.Load(ms);
  22. }
  23. }
  24. }
Add Comment
Please, Sign In to add comment