yeah, you can iterate resources through loops. For example, using foreach
loop:
foreach (var res in Application.Current.Resources)
{
Console.WriteLine(res);
}
Update:
To get all ResourceDictionary'ies
from external library, you should, at first, load the library, then get ManifestResourceInfo
. Let me show an example:
string address = @"WpfCustomControlLibrary.dll";
List<Stream> bamlStreams = new List<Stream>();
Assembly skinAssembly = Assembly.LoadFrom(address);
string[] resourceDictionaries = skinAssembly.GetManifestResourceNames();
foreach (string resourceName in resourceDictionaries)
{
ManifestResourceInfo info = skinAssembly.GetManifestResourceInfo(resourceName);
if (info.ResourceLocation != ResourceLocation.ContainedInAnotherAssembly)
{
Stream resourceStream = skinAssembly.GetManifestResourceStream(resourceName);
using (ResourceReader reader = new ResourceReader(resourceStream))
{
foreach (DictionaryEntry entry in reader)
{
//Here you can see all your ResourceDictionaries
//entry is your ResourceDictionary from assembly
}
}
}
}
You can see all your ResourceDictionary
's in reader
. Please, see the above code.
I've tested this code and it works.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…