当前位置: 首页 > article >正文

wpf devexpress Property Grid创建属性定义

WPF Property Grid控件使用属性定义定义如何做和显示

本教程示范如何绑定WP Property Grid控件到数据和创建属性定义。

执行如下步骤

第一步-创建属性定义

添加PropertyGridControl组件到项目。

打开工具箱在vs,定位到DX.23.1: Data 面板,选择PropertyGridControl工具箱选项,拖动到窗口。

右键点击Property Grid选择Layout | Reset All填充全部窗口:

第二步-创建数据对象

创建数据对象和设置到DataContext

namespace Creating_Definitions {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            DataContext = new Customer() {
                ID = 1,
                FirstName = "Nancy",
                LastName = "Davolio",
                Gender = Gender.Female,
                BirthDate = new DateTime(1948, 8, 12),
                Phone = "7138638137"
            };
        }
        public class Customer {
            public int ID { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public Gender Gender { get; set; }
            public DateTime BirthDate { get; set; }
            public string Phone { get; set; }
        }
        public enum Gender { Male, Female }
    }
}

第三步-绑定Property Grid到Data Object

使用property grid PropertyGridControl.SelectedObject 属性绑定数据

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid" x:Class="PG_lesson1.MainWindow"
        Title="MainWindow" Height="250" Width="525">
    <Grid>

        <dxprg:PropertyGridControl SelectedObject="{Binding}" />

    </Grid>
</Window>

步骤四-创建属性定义

添加属性定义到Property Grid.设置PropertyGridControl.ShowProperties属性ShowPropertiesMode.WithPropertyDefinitions,隐藏未定义属性:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid" x:Class="PG_lesson1.MainWindow"
        Title="MainWindow" Height="250" Width="525">
    <Grid>

        <dxprg:PropertyGridControl SelectedObject="{Binding}" ShowProperties="WithPropertyDefinitions" >
            <dxprg:PropertyDefinition Type="sys:String" />
            <dxprg:PropertyDefinition Path="Gender" />
            <dxprg:PropertyDefinition Path="BirthDate" />
        </dxprg:PropertyGridControl>

    </Grid>
</Window>

运行程序看到结果


http://www.kler.cn/a/132258.html

相关文章:

  • Oracle OCP / MySQL OCP认证容易通过吗
  • es 算法函数 有点不太懂了没有大神给指点一下
  • 【2】SM2验签工具和RSA验签工具
  • 【漏洞复现】IP-guard WebServer 远程命令执行
  • element el-date-picker报错Prop being mutated:“placement“快速解决方式
  • rviz是如何获取图像里选择的点云的3D坐标的
  • vue3 - pinia 中的 storeToRefs
  • 五、函数的介绍
  • 大数据毕业设计选题推荐-机房信息大数据平台-Hadoop-Spark-Hive
  • 初识MongoDB及安装
  • Struts 类型转换之局部和全局配置
  • Redis:java和SpringBoot中使用Redis
  • 小程序里面循环使用ref的话获取不到
  • java:springboot单元测试spring-boot-starter-test
  • UnoCss(原子化css引擎) 让你的开发更轻松愉快
  • 通信原理板块——奇偶监督码、方阵码、恒比码、正反码
  • 千年TGS服务器日志报错如何解决
  • Typora for Mac:打造全新文本编辑体验
  • 【广州华锐互动】VR技术助力中小学生安全教育,让学生在虚拟世界中学会自我保护!
  • 大带宽服务器需要选择哪些节点