Skip to main content

Creating Property Definitions

  • 2 minutes to read

The WPF Property Grid control uses property definitions to define how and which properties are displayed.

This document demonstrates how to bind the WPF Property Grid control to data and create property definitions.

Perform the following steps.

Step 1 — Create a Property Grid

Add a PropertyGridControl component to the project.

To do this, open the Toolbox in Visual Studio, locate the DX.22.1: Data tab, choose the PropertyGridControl Toolbox item, and drop it onto the window.

Right-click the Property Grid and select Layout | Reset All to fill the entire window.


Step 2 — Create a Data Object

Create a data object and set it as the DataContext.

namespace Creating_Definitions {
    public partial class MainWindow : Window {
        public MainWindow() {
            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 }

Step 3 — Bind the Property Grid to the Data Object

Use the property grid’s PropertyGridControl.SelectedObject property to bind it to data.

        xmlns:dxprg="" x:Class="PG_lesson1.MainWindow"
        Title="MainWindow" Height="250" Width="525">

        <dxprg:PropertyGridControl SelectedObject="{Binding}" />


Step 4 — Create Property Definitions

Add property definitions to the property grid. Set the PropertyGridControl.ShowProperties property to ShowPropertiesMode.WithPropertyDefinitions, to hide the properties that do not have definitions.

        xmlns:dxprg="" x:Class="PG_lesson1.MainWindow"
        Title="MainWindow" Height="250" Width="525">

        <dxprg:PropertyGridControl SelectedObject="{Binding}" ShowProperties="WithPropertyDefinitions" >
            <dxprg:PropertyDefinition Type="sys:String" />
            <dxprg:PropertyDefinition Path="Gender" />
            <dxprg:PropertyDefinition Path="BirthDate" />


Run the application to see the result.