C # Extended Toolkit PropertyGrid hidden Partial properties

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.