该方法是通过更改ShowDetail的状态来实现的隐藏属性

首先在引用里右键 管理NuGet程序包 查找extended wpf toolkit 并安装

然后在MainWindow.xaml添加引用 xmlns:extoolkit="http://schemas.xceed.com/wpf/xaml/toolkit" extoolkit为自命名

页面代码如下

<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="350" Width="525">
    <Grid>
        <extoolkit:PropertyGrid Name="propertygrid1"></extoolkit:PropertyGrid>
    </Grid>
</Window>

然后在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;
    }

在MainWindow()里面添加

this.propertygrid1.SelectedObject = new A();

运行程序

当勾选 ShowDetail 时 会显示隐藏的属性 并隐藏当前显示的属性

C# extended toolkit propertygrid 隐藏部分属性的更多相关文章

  1. C#基础系列:开发自己的窗体设计器(PropertyGrid显示中文属性名)

    既然是一个窗体设计器,那就应该能够设置控件的属性,设置属性最好的当然是PropertyGrid了,我们仅仅需要使用一个PropertyGrid.SelectedObject = Control就可以搞 ...

  2. PropertyGrid—隐藏某些Public属性

    1.定义一个继承ControlDesigner 的类 public class MyControlDesigner:System.Windows.Forms.Design.ControlDesigne ...

  3. PropertyGrid—为复杂属性提供下拉式编辑框和弹出式编辑框

    零.引言 PropertyGrid中我们经常看到一些下拉式的编辑方式(Color属性)和弹出式编辑框(字体),这些都是为一些复杂的属性提供的编辑方式,本文主要说明如何实现这样的编辑方式. 一.为属性提 ...

  4. CSS 隐藏 visibility 属性

    定义和用法 visibility 属性规定元素是否可见. 提示:即使不可见的元素也会占据页面上的空间.请使用 "display" 属性来创建不占据页面空间的不可见元素. 说明 这个 ...

  5. PropertyGrid—添加属性Tab

    零.引言 PropertyGrid用来显示和编辑对象的属性,前面已经简单介绍了如何使用该控件和提供不同的属性编辑方法.前面主要讲如何使用该控件,但有时,该控件无法满足我们的需求,就需要对其进行扩展.本 ...

  6. 面向对象 - 1.封装之如何实现属性的隐藏/2.封装的意义/3.封装与扩展性/4.property的使用

    1.封装之如何实现属性的隐藏封装: __x=1 # 把数据属性隐藏 (如何实现隐藏) 类定义阶段 __开头发生了变形 __x --> _A__x特点: 1.在类外部无法直接:obj.__Attr ...

  7. C# PropertyGrid控件应用心得

    何处使用 PropertyGrid 控件 在应用程序中的很多地方,您都可以使用户与 PropertyGrid 进行交互,从而获得更丰富的编辑体验.例如,某个应用程序包含多个用户可以设置的“设置”或选项 ...

  8. C# PropertyGrid控件应用心得 【转】

    源文 : http://blog.csdn.net/luyifeiniu/article/details/5426960 c#stringattributesobjectmicrosoftclass ...

  9. jQuery 的属性

    一.显示和隐藏的属性  hide(隐藏),show(显示) 下面是例子 <script type="text/javascript"> $(document).read ...

随机推荐

  1. Socket编程实践(1) 基本概念

    1. 什么是socket socket可以看成是用户进程与内核网络协议栈的编程接口.TCP/IP协议的底层部分已经被内核实现了,而应用层是用户需要实现的,这部分程序工作在用户空间.用户空间的程序需要通 ...

  2. 封装js的部分兼容性

    //获取标签的内容(兼容所有浏览器)function getInnerText(element) { //能力检测(先判断如果这个能力有这个) if(typeof element.innerText ...

  3. Javascript中JSON对象的操作以及遍历key/value

    //遍历获取值: function text(){ var json = {"options":"[{/"text/":/"王家湾/&quo ...

  4. FineUI配置文件

    <configuration> <configSections> <section name="FineUI" type="FineUI.C ...

  5. 【Beta】Scrum09

    Info 考试周,暂停工作 时间:2016.12.26 21:35 时长:20min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.12.31 21:30 Task Rep ...

  6. W3Help-兼容性-知识库

    http://www.w3help.org/zh-cn/kb/ clear:none/left/right/both/inherit该特性表明元素框的哪一边不可以和先前的浮动框相邻.'clear' 特 ...

  7. Java Annotation概述

    @(Java)[Annotation|Java] Java Annotation概述 用途 编译器的相关信息,如用于检测错误和一些警告 编译时和部署时的处理,如一些软件用于自动生成代码之类的 运行时处 ...

  8. 【mysql函数】FIND_IN_SET函数用法

    当你的数据存储为一下格式时,想查出带有某个id的所有数据时,FIND_IN_SET这个函数可以帮到你. ',C_BranchId)

  9. 一个ListView怎么展示两种样式

    private class MyBaseMsgAdapter extends BaseAdapter { //获取数据适配器中条目类型的总数,修改成两种(纯文本,输入+文字) @Override pu ...

  10. mysql中distinct的用法

    本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...