• wpf devexpress Property Grid创建属性定义


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

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

    执行如下步骤

    第一步-创建属性定义

    添加PropertyGridControl组件到项目。

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

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

    第二步-创建数据对象

    创建数据对象和设置到DataContext

    1. namespace Creating_Definitions {
    2. public partial class MainWindow : Window {
    3. public MainWindow() {
    4. InitializeComponent();
    5. DataContext = new Customer() {
    6. ID = 1,
    7. FirstName = "Nancy",
    8. LastName = "Davolio",
    9. Gender = Gender.Female,
    10. BirthDate = new DateTime(1948, 8, 12),
    11. Phone = "7138638137"
    12. };
    13. }
    14. public class Customer {
    15. public int ID { get; set; }
    16. public string FirstName { get; set; }
    17. public string LastName { get; set; }
    18. public Gender Gender { get; set; }
    19. public DateTime BirthDate { get; set; }
    20. public string Phone { get; set; }
    21. }
    22. public enum Gender { Male, Female }
    23. }
    24. }

    第三步-绑定Property Grid到Data Object

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

    1. <Window
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid" x:Class="PG_lesson1.MainWindow"
    5. Title="MainWindow" Height="250" Width="525">
    6. <Grid>
    7. <dxprg:PropertyGridControl SelectedObject="{Binding}" />
    8. Grid>
    9. Window>

    步骤四-创建属性定义

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

    1. <Window
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:sys="clr-namespace:System;assembly=mscorlib"
    5. xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
    6. xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid" x:Class="PG_lesson1.MainWindow"
    7. Title="MainWindow" Height="250" Width="525">
    8. <Grid>
    9. <dxprg:PropertyGridControl SelectedObject="{Binding}" ShowProperties="WithPropertyDefinitions" >
    10. <dxprg:PropertyDefinition Type="sys:String" />
    11. <dxprg:PropertyDefinition Path="Gender" />
    12. <dxprg:PropertyDefinition Path="BirthDate" />
    13. dxprg:PropertyGridControl>
    14. Grid>
    15. Window>

    运行程序看到结果

  • 相关阅读:
    <Linux基础I/O(2)>——《Linux》
    kafka可视化工具
    使用反射拼接SQL语句 和 使用 反射 + 注解 拼接SQL语句
    Thinkphp5 5.0.22/5.1.29 远程代码执行漏洞 漏洞复现
    STM32 Cubemx Freertos 工程, 用GDB进行debug时候, 跳进HardFault_Handler的问题
    直播美颜SDK对比评测:技术原理与应用实践
    ES6--Promise
    Base64编码
    JavaScript基础第06天笔记——内置对象、简单数据类型和复杂数据类型
    Guava入门~MapMaker
  • 原文地址:https://blog.csdn.net/loongsking/article/details/134455165