Get all XAML files from compiled DLL

c#, wpf, xaml

Solution

You can enumerate the embedded resources of an assembly like this:

var assembly = Assembly.LoadFile("pathToYourAssembly");
var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".g.resources");
var resourceReader = new ResourceReader(stream);

foreach (DictionaryEntry resource in resourceReader)
    Console.WriteLine(resource.Key);

Problem

I want to load during runtime external XAML styles from third-party libraries (DLLs). Like in this tutorial they use: ``` Application.LoadComponent(new Uri("/WpfSkinSample;component/Skins/" + name + ".xaml", UriKind.Relative)) as ResourceDictionary; ``` to load the new style. But I don't know the XAML names from the third-party library, so I'm searching for a way to get them and load them into my application. Thanks for any help. Edit: Thanks to andyp, I did the following work out: ``` public void LoadXaml(String Assemblypath) { var assembly = Assembly.LoadFile(Assemblypath); var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".g.resources"); var resourceReader = new ResourceReader(stream); foreach (DictionaryEntry resource in resourceReader) { if (new FileInfo(resource.Key.ToString()).Extension.Equals(".baml")) { Uri uri = new Uri("/" + assembly.GetName().Name + ";component/" + resource.Key.ToString().Replace(".baml", ".xaml"), UriKind.Relative); ResourceDictionary skin = Application.LoadComponent(uri) as ResourceDictionary; this.Resources.MergedDictionaries.Add(skin); } } } ```

Original source