コントロールを読み取るためのすべてのクラスのXAML
リフレクションを使用してインスタンスを作成することにより、Silverlight プロジェクトを読み込んですべてのファイルを読み取ろうとしています。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 ファイル内のすべてのコントロールを動的に読み取るインスタンスを作成するにはどうすればよいですか?