我正在使用无法修改的第三方类,我想在 winforms propertygrid 中查看它们。问题是网格不允许我扩展嵌套类。它看起来像这样。
第三方代码看起来像这样
[System.Xml.Serialization.XmlRoot("BBB")]
[DataContract]
public class B : INotifyPropertyChanged
{
[DataMember]
private Int32 x;
[DataMember]
private Int32 y;
public Int32 X
{
get{return x; }
set{ x = value;}
}
public Int32 Y
{
get { return y; }
set { y = value;![enter image description here][1]}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
RaisePropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
private void RaisePropertyChanged(object sender, PropertyChangedEventArgs arg)
{
if (PropertyChanged != null)
PropertyChanged(sender, arg);
}
public override string ToString()
{
return string.Format("X {0} , Y {1}", x,y);
}
}
[System.Xml.Serialization.XmlRoot("AAA")]
[DataContract]
public class A : INotifyPropertyChanged
{
[DataMember]
private Int32 i = 18;
[DataMember]
private Int32 j = 6;
[DataMember]
private B b;
public Int32 I
{
get { return i; }
set { i = value; }
}
public Int32 J
{
get { return j; }
set { j = value; }
}
public B BB
{
get { return b; }
set { b = value; }
}
public override string ToString()
{
return string.Format("I {0} , J {1} B {2}", i, j, b.ToString());
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
RaisePropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
private void RaisePropertyChanged(object sender, PropertyChangedEventArgs arg)
{
if (PropertyChanged != null)
PropertyChanged(sender, arg);
}
}
我正在像这样初始化propertygrid
A aa = new A();
propertyGrid2.SelectedObject = aa;