汕头免费建设网站制作,海尔电商网站建设方案,中信建设有限责任公司官网招聘信息,海口网约车最新政策WPF Property Grid控件使用属性定义定义如何做和显示
本教程示范如何绑定WP Property Grid控件到数据和创建属性定义。
执行如下步骤
第一步-创建属性定义
添加PropertyGridControl组件到项目。
打开工具箱在vs#xff0c;定位到DX.23.1: Data 面板#xff0c;选择Prope…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 属性绑定数据
Windowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dxprghttp://schemas.devexpress.com/winfx/2008/xaml/propertygrid x:ClassPG_lesson1.MainWindowTitleMainWindow Height250 Width525Griddxprg:PropertyGridControl SelectedObject{Binding} //Grid
/Window
步骤四-创建属性定义
添加属性定义到Property Grid.设置PropertyGridControl.ShowProperties属性ShowPropertiesMode.WithPropertyDefinitions隐藏未定义属性
Windowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:sysclr-namespace:System;assemblymscorlibxmlns:dxehttp://schemas.devexpress.com/winfx/2008/xaml/editorsxmlns:dxprghttp://schemas.devexpress.com/winfx/2008/xaml/propertygrid x:ClassPG_lesson1.MainWindowTitleMainWindow Height250 Width525Griddxprg:PropertyGridControl SelectedObject{Binding} ShowPropertiesWithPropertyDefinitions dxprg:PropertyDefinition Typesys:String /dxprg:PropertyDefinition PathGender /dxprg:PropertyDefinition PathBirthDate //dxprg:PropertyGridControl/Grid
/Window
运行程序看到结果