Editor Attribute
RadPropertyGrid provides support for the Telerik attribute EditorAttribute that enables the user to define an editor for each property directly in its definition.
EditorAttribute is placed in Telerik.Windows.Controls.Data binary in Telerik.Windows.Controls.Data.PropertyGrid namespace. You need to have a reference to the assembly and add a using for the namespace. You can check the Getting Started with RadPropertyGrid article for more basic information.
It has three properties:
EditorType: Specifies the type of the editor used for the property.
TargetProperty: Defines the property of the custom editor that will be used for the binding.
-
EditorStyle: Sets the style of the UI component used for hosting the custom editor. Its values can be:
DropDown: A dropdown button which content is the custom editor to be displayed.
Modal: A button that shows a modal dialog window with the custom editor inside. Read more about it here.
None (default value): The editor will be placed directly in PropertyGridField and no special UI element will be used.
Constructors
Consequently, EditorAttribute has various constructors that can be used depending on the necessities. Their main difference is that either the Type of the editor is passed as parameter, or the string representation of the editor's Type.
public EditorAttribute(Type editorType)
public EditorAttribute(Type editorType, EditorStyle editorStyle)
public EditorAttribute(Type editorType, string targetProperty)
public EditorAttribute(Type editorType, string targetProperty, EditorStyle editorStyle)
public EditorAttribute(string editorTypeName, string assemblyFile)
public EditorAttribute(string editorTypeName, string assemblyFile, EditorStyle editorStyle)
public EditorAttribute(string editorTypeName, string assemblyFile, string targetProperty)
public EditorAttribute(string editorTypeName, string assemblyFile, string targetProperty, EditorStyle editorStyle)
The assemblyFile parameter represents the absolute file path of the needed assembly
For the purposes of this example, the definition of RadPropertyGrid is:
Example 1: Defining RadPropertyGrid
The property Captain is defined in the ViewModel as follows:
Example 2: Defining property in the ViewModel
The definitions of the Custom editor PhoneEditorControl, the Player business object used and the full implementation of the PhoneNumber class can be found in the Define Data section.
- EditorAttribute(Type editorType) – only the type of the editor can be specified:
Example 3: Specifying the type of the editor
- EditorAttribute(string editorTypeName, string assemblyFile) – the string representation of the editor's type and the absolute file path of the assembly can be specified:
Example 4: Specifying the type of the editor as string and passing the absolute file path of the assembly
It will look like:
Figure 1: EditorAtrribute with editorType specified
- EditorAttribute(Type editorType, EditorStyle editorStyle) – the type of the editor and the style of the containing host:
Example 5: Specifying the type of the editor and the style of the containing host
- EditorAttribute(string editorTypeName, string assemblyFile, EditorStyle editorStyle) - the style of the containing host can be specified:
Example 6: Specifying the type of the editor and the absolute file path of the assembly as string, as well the style of the containing host
In this case PhoneEditorControl will be defined in a DropDownEditor control and it will look like:
Figure 2: EditorAtrribute with editorType and editorStyle specified
- EditorAttribute(Type editorType, string targetProperty) – the type of the editor and its property that you want to bind to. For instance:
Example 7: Specifying the type of the editor and the target property
- EditorAttribute(string editorTypeName, string assemblyFile, string targetProperty) - the target property can be specified:
Example 8: Specifying the type of the editor and the absolute file path of the assembly as string, as well the target property
In this case the property from your business object – Number – will be bound to the ValueProperty of RadNumericUpDown control.
The result will be:
Figure 3: EditorAtrribute with editorType and targetProperty specified
- EditorAttribute(Type editorType, string targetProperty, EditorStyle editorStyle) – with this constructor all properties are set – the type of the editor, its property that will be used for the binding and the type of the host it will be placed inside. For example:
Example 9: Specifying the type of the editor, the target property and style of the containing host
- EditorAttribute(string editorTypeName, string assemblyFile, string targetProperty, EditorStyle editorStyle) - specifying both the target property
Example 10: Specifying the type of the editor and the absolute file path of the assembly as string, the target property and the style for the containing host
It will look like:
Figure 4: EditorAtrribute with editorType, targetProperty and editorStyle specified
Define Data
The definition of the Custom editor PhoneEditorControl is:
Example 11: Defining the custom editor
The definition of the PhoneNumber class is:
Example 12: Defining PhoneNumber object
The definition of the Player business object used for the example is: