• 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>

    运行程序看到结果

  • 相关阅读:
    MT6701磁编码器使用指南,14Bit单圈绝对值,I2C stm32 HAL库读角度
    [Kogel.Subscribe.Mssql]SQL Server增量订阅,数据库变更监听
    基于卷积神经网络的苗语孤立词语音识别
    Hive性能调优实战
    docker升级步骤及注意事项
    [附源码]Python计算机毕业设计Django新能源汽车租赁
    随机产生一个1-100之间的整数,看能几次猜中
    软考的网络工程师对就业有用吗?
    [React Hooks]性能调优与自定义钩子
    Collections.addAll()和list.addAll()不同之处说明
  • 原文地址:https://blog.csdn.net/loongsking/article/details/134455165