Filtering
The property grid includes advanced filtering support, which can be used to narrow down the items that are displayed. Built-in filters can be applied to several properties and can be combined into groups. Filter groups can perform a logical AND or OR operation on the child filters, and several levels of groups can be used for total control. String filters offer several comparison options including regular expressions.
Filter Infrastructure
The Tree Controls Filtering topic describes the core filtering mechanism used by property grid. Please review that topic first since PropertyGrid indirectly inherits TreeListBox and harnesses the same core filtering mechanism for its own filtering.
Property grid comes with a couple built-in filters that are designed to filter common properties on property models. These are described in the following sections.
Note
To activate filtering functionality, set the IsFilterActive property to true
. It is false
by default. For optimal performance, keep it false
unless you have a DataFilter set and you are actively want to filter displayed properties.
Built-in PropertyModelStringFilter
The PropertyModelStringFilter class is an IDataFilter implementation for IPropertyModel string properties. It inherits StringFilterBase and all of the information in the Tree Controls Filtering topic related to "String Filters" applies. There are numerous comparison operators available, and even regular expressions are supported.
The PropertyModelStringFilter class introduces a Source property that accepts a PropertyModelStringFilterSource value and defaults to DisplayName
.
That enumeration has these values:
Value | Description |
---|---|
Category |
The IPropertyModel.Category property should be used as the source. |
Description |
The IDataModel.Description property should be used as the source. |
DisplayName |
The IDataModel.DisplayName property should be used as the source. |
Name |
The IDataModel.Name property should be used as the source. |
ValueType |
The IPropertyModel.ValueType property should be used as the source. |
This code shows how to only show properties that contain "is"
in their display names:
<grids:PropertyGrid ... IsFilterActive="True">
<grids:PropertyGrid.DataFilter>
<grids:PropertyModelStringFilter x:Name="stringFilter" Source="DisplayName" Operation="Contains" Value="is" />
</grids:PropertyGrid.DataFilter>
</grids:PropertyGrid>
Built-in PropertyModelBooleanFilter
The PropertyModelBooleanFilter class is an IDataFilter implementation for IPropertyModel boolean properties. It inherits BooleanFilterBase and all of the information in the Tree Controls Filtering topic related to "Boolean Filters" applies. There are numerous comparison operators available.
The PropertyModelBooleanFilter class introduces a Source property that accepts a PropertyModelBooleanFilterSource value and defaults to IsReadOnly
.
That enumeration has these values:
Value | Description |
---|---|
CanResetValue |
The IPropertyModel.CanResetValue property should be used as the source. |
HasStandardValues |
The IPropertyModel.HasStandardValues property should be used as the source. |
IsLimitedToStandardValues |
The IPropertyModel.IsLimitedToStandardValues property should be used as the source. |
IsMergeable |
The IPropertyModel.IsMergeable property should be used as the source. |
IsModified |
The IDataModel.IsModified property should be used as the source. |
IsReadOnly |
The IPropertyModel.IsReadOnly property should be used as the source. |
This code shows how to apply a filter that excludes read-only properties:
<grids:PropertyGrid ... IsFilterActive="True">
<grids:PropertyGrid.DataFilter>
<grids:PropertyModelBooleanFilter x:Name="booleanFilter" Source="IsReadOnly" Operation="Equals" Value="False" />
</grids:PropertyGrid.DataFilter>
</grids:PropertyGrid>
Group Filters
Multiple filters like PropertyModelStringFilter and PropertyModelBooleanFilter can be combined in a group with logical AND or OR operators to return a filter result.
See the Tree Controls Filtering topic for details on using group filters.
This code shows how to only show properties that contain "is"
in their display names and aren't read-only:
<grids:PropertyGrid ... IsFilterActive="True">
<grids:PropertyGrid.DataFilter>
<shared:DataFilterGroup x:Name="filterGroup">
<grids:PropertyModelStringFilter x:Name="stringFilter" Source="DisplayName" Operation="Contains" Value="is" />
<grids:PropertyModelBooleanFilter x:Name="booleanFilter" Source="IsReadOnly" Operation="Equals" Value="False" />
</shared:DataFilterGroup>
</grids:PropertyGrid.DataFilter>
</grids:PropertyGrid>
Predicate or Custom Filters
Predicates or completely custom filters can be created as well. See the Tree Controls Filtering topic for details on using predicate or custom filters.