Reputation: 70327
Can anyone help me to know how to list all of the XAML pages in an assembly ?
Upvotes: 0
Views: 206
Reputation: 3800
If you are looking for pages that were compiled into the xap, then you can enumerate the embedded xaml by using code like the following:
string assemblyFullName = System.Reflection.Assembly.GetExecutingAssembly().ToString();
string baseName = assemblyFullName.Substring(0, assemblyFullName.IndexOf(",")) + ".g";
ResourceManager manager = new ResourceManager(baseName, System.Reflection.Assembly.GetExecutingAssembly());
var set = manager.GetResourceSet(System.Globalization.CultureInfo.InvariantCulture, true, true);
foreach (DictionaryEntry resource in set)
{
if (resource.Key.ToString().EndsWith(".xaml"))
{
var doc = XDocument.Load(resource.Value as Stream);
if (doc.Root.Name == "{clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone}PhoneApplicationPage")
{
System.Diagnostics.Debug.WriteLine(resource.Key.ToString() + " is a Page");
}
}
}
Upvotes: 2
Reputation: 26336
Use reflection, of course:
var assembly = Assembly.GetExecutingAssembly();
var pages = assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(PhoneApplicationPage)));
Upvotes: 3