PropertyGrid
The controls provided in the Editors product can be easily integrated into the PropertyGrid control, through the use of custom property editors. In order to keep both products segregated, an Interop assembly is provided that ties the two products together.
PropertyGrid with BrushEditBox integrated
Interop Assembly
The Interop functionality is provided through a separate assembly, which is called ActiproSoftware.Editors.Interop.Grids.Wpf.dll. Therefore, a reference to this assembly must be added in order to leverage the property editors it provides. This assembly should have been installed in the GAC during the control installation process. However, they also will be located in the appropriate Program Files folders. See the product's Readme for details on those locations.
Property Editors
The PropertyGrid uses "property editors" to tie a properties to controls, by property name and/or property type. For example, you can tell the PropertyGrid that all properties of the type DateTime
should use MyControlA
and all properties of the type String
should use MyControlB
. This gives you a lot of control over what control is used for the various properties. In reality, the "control" is actually a DataTemplate
since it will most likely be used multiple times.
Property editors are defined via an instance of the PropertyEditor class. Derivations of this class can provide default values, such as a known DataTemplate
or property Type
. In addition, derivations are required in order to decorate properties with EditorAttribute
. EditorAttribute
only allows the editor Type
to be specified, therefore that Type
needs to provide a default DataTemplate
(via a derivation of PropertyEditor).
Note
Property editors can actually provide a DataTemplate
for the value cell and the name cell, but typically the name cell does not need to be altered.
See the Property Editors topic under Actipro PropertyGrid for more information.
The Interop assembly provides a set of classes that derive from PropertyEditor and provide default values for the DataTemplate
used for the value cell and the property Type
. These classes include:
Class | Description |
---|---|
Represents a property editor that uses a BrushEditBox for editing |
|
Represents a property editor that uses a ByteEditBox for editing |
|
Represents a property editor that uses a ColorEditBox for editing |
|
Represents a property editor that uses a CornerRadiusEditBox for editing |
|
Represents a property editor that uses a DateEditBox for editing |
|
Represents a property editor that uses a DateTimeEditBox for editing |
|
Represents a property editor that uses a DoubleEditBox for editing |
|
Represents a property editor that uses a EnumEditBox for editing |
|
Represents a property editor that uses a GuidEditBox for editing |
|
Represents a property editor that uses a Int16EditBox for editing |
|
Represents a property editor that uses a Int32EditBox for editing |
|
Represents a property editor that uses a Int32RectEditBox for editing |
|
Represents a property editor that uses a Int64EditBox for editing |
|
Represents a property editor that uses a MaskedTextBox for editing property values. |
|
Represents a property editor that uses a ByteEditBox for editing |
|
Represents a property editor that uses a ColorEditBox for editing |
|
Represents a property editor that uses a CornerRadiusEditBox for editing |
|
Represents a property editor that uses a DateEditBox for editing |
|
Represents a property editor that uses a DateTimeEditBox for editing |
|
Represents a property editor that uses a DoubleEditBox for editing |
|
Represents a property editor that uses a GuidEditBox for editing |
|
Represents a property editor that uses a Int16EditBox for editing |
|
Represents a property editor that uses a Int32EditBox for editing |
|
Represents a property editor that uses a Int32RectEditBox for editing |
|
Represents a property editor that uses a Int64EditBox for editing |
|
Represents a property editor that uses a PointEditBox for editing |
|
Represents a property editor that uses a RectEditBox for editing |
|
Represents a property editor that uses a SingleEditBox for editing |
|
Represents a property editor that uses a SizeEditBox for editing |
|
Represents a property editor that uses a ThicknessEditBox for editing |
|
Represents a property editor that uses a TimeEditBox for editing |
|
Represents a property editor that uses a TimeSpanEditBox for editing |
|
Represents a property editor that uses a VectorEditBox for editing |
|
Represents a property editor that uses a PointEditBox for editing |
|
Represents a property editor that uses a RectEditBox for editing |
|
Represents a property editor that uses a SingleEditBox for editing |
|
Represents a property editor that uses a SizeEditBox for editing |
|
Represents a property editor that uses a ThicknessEditBox for editing |
|
Represents a property editor that uses a TimeEditBox for editing |
|
Represents a property editor that uses a TimeSpanEditBox for editing |
|
Represents a property editor that uses a VectorEditBox for editing |
Each property editor exposes some of the more common settings available on their associated control. For example, the MaskedStringPropertyEditor has a Mask property that allows you to set the associated Mask on the underlying MaskedTextBox. Remember that the controls are defined using a DataTemplate
, so normally it is not easy to access the settings on the controls. Using the settings available on the property editor, the underlying controls can be quickly configured.
Adding to PropertyGrid
The property editors provided can be added to a PropertyGrid using several methods, which are described below.
All Default Property Editors
All default Editors integration property editors can be easily injected into a single PropertyGrid instance by setting the attached BuiltinPropertyEditors.IsEnabled
property to true
.
Note
Setting this attached property simply appends our Editors integration property editors to the PropertyGrid.PropertyEditors collection. You can add your own customized property editors to that collection through XAML too, and your custom property editors will be appended after our default Editors integration property editors. This gives your custom property editors higher priority for selection over ours.
This can be done on the specific instance or via an implicit Style
that targets all PropertyGrid instances in the app.
This code adds the required xmlns
definitions:
xmlns:grids="http://schemas.actiprosoftware.com/winfx/xaml/grids"
xmlns:gridseditors="http://schemas.actiprosoftware.com/winfx/xaml/gridseditors"
This code shows how add the default Editors integration property editor definitions to a single PropertyGrid
:
<grids:PropertyGrid ... gridseditors:BuiltinPropertyEditors.IsEnabled="True">
...
</grids:PropertyGrid>
If you wish to apply the property editors provided to all property grid instances in the application, the attached BuiltinPropertyEditors.IsEnabled
property can be set to true
on a PropertyGridPropertyEditorsModifier object that you define in Application.Resources
. Please see the Property Editors topic under Actipro PropertyGrid for more information on defining property editors in XAML using PropertyGridPropertyEditorsModifier.
Note
There are several property editors that cannot be installed via the built-in editors property described above and must be manually added to a PropertyGrid.PropertyEditors collection:
- DatePropertyEditor - Targets
DateTime
and normally the DateTimePropertyEditor handles that. - MaskedStringPropertyEditor - Targets
String
and requires that aMask
is set. - NullableDatePropertyEditor - Targets
DateTime?
and normally the NullableDateTimePropertyEditor handles that. - NullableTimePropertyEditor - Targets
DateTime?
and normally the NullableDateTimePropertyEditor handles that. - TimePropertyEditor - Targets
DateTime
and normally the DateTimePropertyEditor handles that.
Specific Property Editors via PropertyGrid.PropertyEditors
Property editors can also be manually defined on a single instance of the PropertyGrid control by updating the PropertyEditors collection.
Several property editors (described above) require this since they can't be automatically set up by the built-in editors property. Note that you can apply the built-in editor and manually-defined editors on the same property grid.
This code shows how manually add several property editor definitions to a single PropertyGrid
:
<grids:PropertyGrid ... >
<grids:PropertyGrid.PropertyEditors>
<gridseditors:DatePropertyEditor PropertyName="DateLongValue" Format="D" />
<gridseditors:MaskedStringPropertyEditor PropertyName="MaskedString" Mask="\w+([.]\w+)*@\w+([.]\w+)+" />
<gridseditors:EnumPropertyEditor UseDisplayAttributes="True" />
</grids:PropertyGrid.PropertyEditors>
</grids:PropertyGrid>
Using EditorAttribute
A property editor can also be associated right on the data objects displayed by PropertyGrid using the EditorAttribute
.
This code shows how associated a ColorEditBox
property editor with a property:
[Editor(typeof(ColorPropertyEditor), typeof(PropertyEditor))]
public Color MyColor {
...
}
Since EditorAttribute
only allows a Type
to be specified, if you need to alter any default property values, create a class that inherits the desired property editor Type
and set the property values in the class' constructor.