オブジェクトの子プロパティの問題の値、私はこのコードを持つオブジェクトの子プロパティを取得
PropertyDescriptorCollection childProperties = TypeDescriptor.GetProperties(theObject)childNode.Name] .GetChildProperties()を設定します。
"theObject"変数はTextBoxであり、TextBox.Font.Bold = trueを設定しようとします。
メインプロパティにこのコードを使用し、メインプロパティをカスタマイズすると機能します。しかし、子プロパティにアクセスすると、 "オブジェクト参照がオブジェクトのインスタンスに設定されていません"というエラーが表示されます。
その後、
<TextBox>
<Font Bold="true"/>
</Textbox>
そして、あなたは、テキストボックスのFont
プロパティを取得:それの顔に、それはあなたのような何かを得るように見える - あなたはSetValue
に間違ったオブジェクトを渡しているよう
foreach (PropertyDescriptor childProperty in childProperties)
{
foreach (XmlAttribute attribute in attributes)
{
if (childProperty.Name == attribute.Name)
{
if (!childProperty.IsReadOnly)
{
object convertedPropertyValue = ConverterHelper.ConvertValueForProperty(attribute.Value, childProperty);
childProperty.SetValue(theObject, convertedPropertyValue); //exception throw here
break;
}
}
}
}
完全な例外を貼り付けることができます –