我正在尝试加载一个 Silverlight 项目来读取每个文件,方法是使用每个类的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 文件中的每个控件?