我想加載一個Silverlight項目來讀取每個XAML
文件,方法是使用每個XAML
類的反射Activator.CreateInstance
來創建一個實例來讀取其控件。如何動態加載XAML獲取控件信息
C#代碼:
string strPath = "SilverlightUI.dll";
StreamResourceInfo sri = Application.GetResourceStream(new Uri(strPath, UriKind.RelativeOrAbsolute));
AssemblyPart assemblyPart = new AssemblyPart();
Assembly assembly = assemblyPart.Load(sri.Stream);
Type[] typeArray = assembly.GetExportedTypes();
foreach (Type type in typeArray)
{
object ctl = (object)Activator.CreateInstance(type);
// Following exception is occurring while creating an instance using above line of code
// Exception "Cannot find a Resource with the Name/Key ComboBoxStyle"
}
或許,反思是不是能夠識別的Silverlight風格ComboBoxStyle
。我怎麼可能創建一個實例動態讀取XAML文件中的每個控件?