超級(jí)seo外鏈seo的推廣技巧
WPF Property Grid控件使用屬性定義定義如何做和顯示
本教程示范如何綁定WP Property Grid控件到數(shù)據(jù)和創(chuàng)建屬性定義。
執(zhí)行如下步驟
第一步-創(chuàng)建屬性定義
添加PropertyGridControl組件到項(xiàng)目。
打開(kāi)工具箱在vs,定位到DX.23.1: Data 面板,選擇PropertyGridControl工具箱選項(xiàng),拖動(dòng)到窗口。
右鍵點(diǎn)擊Property Grid選擇Layout | Reset All填充全部窗口:
第二步-創(chuàng)建數(shù)據(jù)對(duì)象
創(chuàng)建數(shù)據(jù)對(duì)象和設(shè)置到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 屬性綁定數(shù)據(jù)
<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>
步驟四-創(chuàng)建屬性定義
添加屬性定義到Property Grid.設(shè)置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>
運(yùn)行程序看到結(jié)果