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

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 属性绑定数据

<Windowxmlns="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,隐藏未定义属性:

<Windowxmlns="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.lryc.cn/news/233414.html

相关文章:

  • 78.子集--77.组合
  • 【C++】模版-初阶
  • 【JavaEE初阶】 TCP服务器与客户端的搭建
  • 23111710[含文档+PPT+源码等]计算机毕业设计基于SpringBoot的体育馆场地预约赛事管理系统的设计
  • 【论文解读】GPT Understands, Too
  • 组合式API_生命周期
  • WPF如何实现应用程序托盘
  • ERROR: column “xxxx.id“ must appear in the GROUP BY
  • 【C++ 学习 ㊲】- 五种特殊类的设计
  • 探索arkui(2)--- 布局(列表)--- 2(支持分组/实现响应滚动位置)
  • systemverilog:interface中端口方向理解
  • 【GUI】-- 08 JButton、JRadioButton、JCheckBox
  • 【postgresql】CentOS7 安装Pgweb
  • 基于python和定向爬虫的商品比价系统
  • 使用GPT-4训练数据微调GPT-3.5 RAG管道
  • 二十三种设计模式全面解析-深入解析模板方法模式的奇妙世界
  • 【Spring】加载properties文件
  • react中间件的理解
  • React函数组件状态Hook—useState《进阶-对象数组》
  • linux 网络 cat /proc/net/dev 查看测试网络丢包情况
  • 记录配置VS,使用opencv与Eigen
  • uart控制led与beep
  • Linux修改root密码
  • C/C++模板类模板与函数模板区别,以及用法详解
  • van-dialog弹窗异步关闭-校验表单
  • Dynamic Wallpaper 16.7中文版
  • ​如何使用ArcGIS Pro制作渐变河流效果
  • 《网络协议》06. HTTP 补充 · HTTPS · SSL/TLS
  • Python winreg将cmd/PowerShell(管理员)添加到右键菜单
  • redis运维(九)字符串(二)字符串过期时间