CollectionEditors
CollectionEditor and CollectionEditorPicker are editor controls that provide UI for editing collections and their items. Currently they are used in the domain of RadPropertyGrid as default editors for IEnumerable type-compatible properties, but they can be successfully used out of this context as standalone editors:
Example 1: Defining CollectionEditor
If you want CollectionEditor to work with a custom collection, then the edited collection type should implement ICollectionView and IEditableCollectionView interfaces.
Dependencies
Both of them are located in the Telerik.Windows.Controls.Data assembly (Telerik.Windows.Controls.Data.PropertyGrid namespace) and depend on the following assemblies:
Telerik.Windows.Data
Telerik.Windows.Controls
Telerik.Windows.Controls.Data
Telerik.Windows.Control.Input
Internal Structure
CollectionEditor relies on the IEditableCollectionView interface. In case that the edited collection type implements ICollectionView and IEditableCollectionView, its custom implementation is utilized and if it does not, an instance of QueryableCollectionView is used instead.
The following listed commands, defined in the CollectionEditorCommands class, invoke their IEditableCollectionView method counterparts, when they are executed:
MoveCurrentToNext
MoveCurrentToPrevious
AddNew
Delete
Customizing Commands
It is possible to customize the default commands for the CollectionEditor and the CollectionEditorPicker in a MVVM-friendly way. The following examples are using the CollectionEditor control but the same changes can be applied for the CollectionEditorPicker as well.
“Execute logic” methods
The methods listed below identify the logic that is executed when a certain command’s invocation takes place.
Example 3: CollectionEditor's executable commands
“Can-execute logic” methods
With the help of those methods you can identify whether a certain command can be executed or not.
Example 4: CollectionEditor's "can-execute" methods
Designing a custom CommandProvider
The first step is to create your own class that inherits from CollectionNavigatorBaseCommandProvider:
Example 5: Creating a class that provides the custom commands
Those commands, which logic is up to get customized, should have their corresponding methods overridden. In the following example we will customize: MoveCurrentToNext, MoveCurrentToPrevious.
MoveCurrentToNext and MoveCurrentToPrevious
In case you have a requirement to ask for the customer`s approval when moving through items, you need to update the commands as in the following examples:
Example 6: Overriding the default commands
The last thing to be done is to set CommandProvider Property of the CollectionEditor to be the newly-created CustomCommandProvider class:
Example 7: Assigning the CommandProvider
Example 8: Assigning the CommandProvider
Modifying the methods will result in the following action when trying to move to the next item:
Add/Remove Items
CollectionEditor allows you to add and remove items to the underlying collection through the Add and Remove buttons. The availability of this functionality relies on the type of the bound collection and whether it supports such operations. Figure 1 and Figure 2 show the state of the buttons when the CollectionEditor is bound to an ObservableCollection and an Array respectively.
The business object should expose a default constructor in order to have the "Add" button enabled.