The default behavior for DataUiGrid is to reflect properties from the assigned Instance. When the Instance is assigned, the Grid automatically populates its Categories with members based on reflection.
Properties which have the System.ComponentModel.CategoryAttribute
will be categorized according to the category assigned. Otherwise, properties will be put in the Uncategorized category.
By default all public fields and properties are displayed in a DataUiGrid. To control which properties are shown, the categories can be cleared, and individual InstanceMembers can be added for the desired properties.
For example, the following code clears the properties, and shows only X, Y, and Z:
The DataUiGrid is similar to Winforms PropertyGrid - a reflection-based UI object which can be used to display the properties on objects in real-time. It is used for the properties on Gum objects, but is written to be general purpose to be used in any applications.
It is included in the WpfDataUi.dll file which is part of Gum, so this library can be pulled out and used in any other application.
The DataUiGrid can be used with reflection or its Categories can be manually populated. Using reflection is easier to set up, but does not provide as much flexibility. Manually building up Categories takes more work, but provide the most flexibility.
The following references are needed for displaying the DataUiGrid:
PresentationCore
PresentationFramework
System.Xaml
WindowsBase
To add a grid to your XAML you'll need to:
If using .NET 6+, add the following using:
If using .NET 4.7, add the following using:
Add the following inside a layout container (like a Grid):
You can construct a grid in code just like any other WPF control.
To use the grid in code you simply need to set its Instance member to an instance object you want to view. For example:
This will produce a grid which looks like this:
Alternatively the Instance property can be data bound as shown in the following XAML:
The Categories member provides more detailed control over a DataUiGrid. The easiest way to work with a DataUiGrid is to assign its Instance and let it automatically create UI for all public members. Working with Categories requires more code but gives the most flexibility in setting up a grid.
The following makes the grid only show a single value called "Some Value" which always has a value of 10. An actual implementation may modify some backing variable.