我想加载一个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文件中的每个控件?