Version

Property Item Generators (xamPropertyGrid)

Topic Overview

Purpose

This topic explains how the control discovers properties on the selected object(s), generates the list of property items and how the process can be configured and customized.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic explains the features supported by the control from developer perspective.

This topic provides an overview of the visual elements of the control.

Property Generation Introduction

Property generation summary

The xamPropertyGrid control has an extensible architecture for discovering properties on the selected object(s). This architecture is based on the concept of property generators. The following built-in property generators are supplied with the control:

  • TypeDescriptorPropertyGenerator is using TypeDescriptor to discover the properties exposed by the selected object(s). The TypeDescriptor approach will typically discover more properties on the selected object(s) since Attached properties as well as custom properties provided by CustomTypeDescriptor implementations are discoverable and therefore included in the generated list of property items.

  • ReflectionPropertyGenerator is using Reflection to discover the properties of the selected object(s) and can only discover the properties that are explicitly defined on the selected objects(s) type(s).

Note
Note

The required property generator is specified by setting the control’s PropertyGenerator property. If this property is not set, a TypeDescriptor property generator will be used by default.

Configuring property generation

The property generators can be configured using the PropertyGenerationOptions property which allows you to include attached and/or read-only properties.

You can also use filters to customize the properties discovered by the property generators using the GeneratedPropertyFilter property which is shown in the code snippets below.

Custom property generators

If you need custom property generation that "tweaks" the output of the default generators you can derive your own class from one of the built-in property generators and override the GenerateProperties method to modify the property list returned from the built-in generators.

If you need to completely take over the property generator process to implement custom property discovery logic, you can create your own property generator extending from the PropertyGeneratorBase class and override the GenerateProperties method.

Configuring Property Generator Filter

Overview

The following code example demonstrates how to set the reflection property generator and set its filter to show only properties which contains the words "Brush" or "Color" in their names.

Example

Following is the code that implements this example.

In XAML:

<ig:XamPropertyGrid … >
  …
  <ig:XamPropertyGrid.PropertyGenerator>
    <ig:ReflectionPropertyGenerator>
      <ig:ReflectionPropertyGenerator.GeneratedPropertyFilter>
        <ig:PropertyGridConditionGroup LogicalOperator="Or">
          <ig:PropertyGridComparisonCondition Operator="Contains" Value="Brush" />
          <ig:PropertyGridComparisonCondition Operator="Contains" Value="Color" />
        </ig:PropertyGridConditionGroup>
      </ig:ReflectionPropertyGenerator.GeneratedPropertyFilter>
    </ig:ReflectionPropertyGenerator>
  </ig:XamPropertyGrid.PropertyGenerator>
  …
</ig:XamPropertyGrid>

Configuring Property Generator Options

Overview

The following code example demonstrates how to set the type descriptor property generator and how to configure its options to not include attached properties but to include read-only properties.

Example

Following is the code that implements this example.

In XAML:

<ig:XamPropertyGrid … >
  …
  <ig:XamPropertyGrid.PropertyGenerator>
    <ig:TypeDescriptorPropertyGenerator />
  </ig:XamPropertyGrid.PropertyGenerator>
  <ig:XamPropertyGrid.PropertyGenerationOptions>
    <ig:PropertyGenerationOptions
      IncludeAttachedProperties="False" />
      IncludeReadOnlyProperties="True" />
  </ig:XamPropertyGrid.PropertyGenerationOptions>
  …
</ig:XamPropertyGrid>

Related Content

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how the control identifies and displays expandable properties.

This topic explains how to define default property value and how to customize the options menu.

This topic explains how to perform different operations with the control using commands.