This method is a hidden property that is implemented by changing the state of the ShowDetail
First in the references right-click on the Manage NuGet package to find extended WPF toolkit and install
Then add the reference xmlns:extoolkit= "Http://schemas.xceed.com/wpf/xaml/toolkit" Extoolkit for the self-naming in MainWindow.xaml
The page code is as follows
<window x:class= "Toolkitpropertygrid.mainwindow"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
Xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
Xmlns:local= "Clr-namespace:toolkitpropertygrid"
xmlns:extoolkit= "Http://schemas.xceed.com/wpf/xaml/toolkit"
Mc:ignorable= "D"
Title= "MainWindow" height= "width=" 525 ">
<Grid>
<extoolkit:propertygrid name= "Propertygrid1" ></extoolkit:PropertyGrid>
</Grid>
</Window>
and add it to the MainWindow.xaml.cs.
[TypeConverter (typeof (A.propertyconverter))]
class A
{
[Refreshproperties (Refreshproperties.all)]
public bool ShowDetail {get {return showdetail;} set {showdetail = value;}}
public string Summary {get {return Summary;} set {Summary = value;}}
public string Address1 {get {return address1;} set {Address1 = value;}
public string Address2 {get {return address2;} set {address2 = value; } }
Private class Propertyconverter:expandableobjectconverter
{
public override PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value, attribute[] attributes)
{
PropertyDescriptorCollection collection = Typedescriptor.getproperties (value, false);
list< propertydescriptor> list = new list<propertydescriptor> ();
list. ADD (collection["ShowDetail"]);
if (value as A). ShowDetail)
{
List. ADD (collection["Address1"]);
List. ADD (collection["Address2"]);
}
Else
{
List. ADD (collection["Summary"]);
}
return new PropertyDescriptorCollection (list. ToArray ());
}
}
private bool ShowDetail;
private string summary, Address1, address2;
}
Add in MainWindow ()
This.propertygrid1.SelectedObject = new A ();
Run the program
When ShowDetail is checked, hidden properties are displayed and the currently displayed properties are hidden
C # Extended Toolkit PropertyGrid hidden Partial properties