WPF hc:PropertyGrid 嵌套显示

重点:

编写Edit特性即可:

复制代码
public class ParameterEditor : PropertyEditorBase
	{
		public override FrameworkElement CreateElement(PropertyItem propertyItem)
		{
			
			var pg = new PropertyGrid();
            return pg;
		}
        public override DependencyProperty GetDependencyProperty() => PropertyGrid.SelectedObjectProperty;
	}

使用:

复制代码
  private Parameter _parameterInfo = new Parameter();
      
		[Category("参数"), Browsable(true), ReadOnly(false), DisplayName("XX参数"), Editor(typeof(ParameterEditor),typeof(PropertyEditorBase))]
        public Parameter ParameterInfo
		{
	        get => _parameterInfo ;
	        set => Set(ref _parameterInfo , value);
        }

Parameter 类是自定义类,里面可以定义其他想显示的属性。

Editor(typeof(ParameterEditor),typeof(PropertyEditorBase))(这句代码其实很难找,源码并没有直接使用Editor特性,而是动态反射产生的。)

效果:

可以自己定义新样式来优化界面哦

相关推荐
Xin_ye100861 天前
第三章:内存泄漏的常见“案发现场”
c#·wpf
心平气和量大福大2 天前
C#-WPF-UserControl-生命周期(加载 退出)
开发语言·c#·wpf
czhc11400756632 天前
7.23:Claude code:注册->封表
wpf
心平气和量大福大2 天前
C#-WPF-控件-TextBox 数据绑定
开发语言·c#·wpf
listening7773 天前
HarmonyOS 6.1 全场景协同实战:从“单机”到“超级终端”的分布式重构
wpf
心平气和量大福大3 天前
C#-WPF-布局-Grid
c#·wpf·visual studio
心平气和量大福大4 天前
C#-WPF-Window主窗体
开发语言·c#·wpf
FuckPatience4 天前
Telerik UI for WPF 值不能为null。参数名:key
ui·wpf
lindexi5 天前
WPF 笔迹延迟优化从硬件到软件的全链路分析
wpf
weixin_727535626 天前
双Token认证体系深度拆解:Spring Security + JWT + Redis
redis·spring·wpf