C# extended toolkit propertygrid 隐藏部分属性
该方法是通过更改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 隐藏部分属性的更多相关文章
- C#基础系列:开发自己的窗体设计器(PropertyGrid显示中文属性名)
既然是一个窗体设计器,那就应该能够设置控件的属性,设置属性最好的当然是PropertyGrid了,我们仅仅需要使用一个PropertyGrid.SelectedObject = Control就可以搞 ...
- PropertyGrid—隐藏某些Public属性
1.定义一个继承ControlDesigner 的类 public class MyControlDesigner:System.Windows.Forms.Design.ControlDesigne ...
- PropertyGrid—为复杂属性提供下拉式编辑框和弹出式编辑框
零.引言 PropertyGrid中我们经常看到一些下拉式的编辑方式(Color属性)和弹出式编辑框(字体),这些都是为一些复杂的属性提供的编辑方式,本文主要说明如何实现这样的编辑方式. 一.为属性提 ...
- CSS 隐藏 visibility 属性
定义和用法 visibility 属性规定元素是否可见. 提示:即使不可见的元素也会占据页面上的空间.请使用 "display" 属性来创建不占据页面空间的不可见元素. 说明 这个 ...
- PropertyGrid—添加属性Tab
零.引言 PropertyGrid用来显示和编辑对象的属性,前面已经简单介绍了如何使用该控件和提供不同的属性编辑方法.前面主要讲如何使用该控件,但有时,该控件无法满足我们的需求,就需要对其进行扩展.本 ...
- 面向对象 - 1.封装之如何实现属性的隐藏/2.封装的意义/3.封装与扩展性/4.property的使用
1.封装之如何实现属性的隐藏封装: __x=1 # 把数据属性隐藏 (如何实现隐藏) 类定义阶段 __开头发生了变形 __x --> _A__x特点: 1.在类外部无法直接:obj.__Attr ...
- C# PropertyGrid控件应用心得
何处使用 PropertyGrid 控件 在应用程序中的很多地方,您都可以使用户与 PropertyGrid 进行交互,从而获得更丰富的编辑体验.例如,某个应用程序包含多个用户可以设置的“设置”或选项 ...
- C# PropertyGrid控件应用心得 【转】
源文 : http://blog.csdn.net/luyifeiniu/article/details/5426960 c#stringattributesobjectmicrosoftclass ...
- jQuery 的属性
一.显示和隐藏的属性 hide(隐藏),show(显示) 下面是例子 <script type="text/javascript"> $(document).read ...
随机推荐
- NSRunLoop的进一步理解
iPhone应用开发中关于NSRunLoop的概述是本文要介绍的内容,NSRunLoop是一种更加高明的消息处理模式,他就高明在对消息处理过程进行了更好的抽象和封装,这样才能是的你不用处理一些很琐碎很 ...
- iOS中获取当前时间,设定时间,并算出差值
NSDate *date = [NSDate date];//获取当前时间 NSTimeZone *zone = [NSTimeZone systemTimeZone];//修改时区 NSIntege ...
- JS this指向
正常模式 在正常模式下独立函数的的 this 指向 undefined 或 window. <script type="text/javascript"> functi ...
- favicon.ico 404的问题(title栏前面的图标)
1.页面中自定义图标 去 http://www.bitbug.net/ 定制图片,有32*32,16*16等样式可供选择 2.在页面中引入定义的图片 <link rel="sho ...
- UVA227
步骤:1.把输入的数字和空格保存.(这里用到gets函数读取整行)2.定位空格.3.输入指令. #include<stdio.h> #include<string.h> ][] ...
- 问题记录:JavaFx 鼠标滑轮滚动事件监听!
问题描述: 在listview的item里面添加鼠标拖拽排序功能.代码如下: setOnMouseDragged(event -> { //设定鼠标长按0.3秒后才可拖拽 防止误操作 isCan ...
- 11 Set和Map数据结构
Set和Map数据结构 Set WeakSet Map WeakMap 首先 这四个对象都是 数据结构. 用于存放数据 Set 类似数组. 但是不能重复. 如果你有重复数据,会自动忽略 属性 size ...
- Android Automotive开发之一《环境: JDK7&JDK8切换 》
http://ubuntuhandbook.org/index.php/2015/01/install-openjdk-8-ubuntu-14-04-12-04-lts/ 安装OpenJDK8 sud ...
- webapi-创建项目
- git rebase
git rebase -i HEAD~[number_of_commits] git rebase -i HEAD~2