Customizing Commands
This article will demonstrate how to customize RadDataForm's commands in an MVVM-friendly way as well as how to execute them manually.
- The DataFormCommandProvider
- Designing a Custom DataFormCommandProvider
- Setting the Custom DataFormCommandProvider
- Executing Commands Manually
The DataFormCommandProvider
The public DataFormCommandProvider class exposes the "execute" and "can-execute" logic of all commands utilized by RadDataForm. RadDataForm processes these commands according to its current provider.
Execute Logic Methods
The methods listed below identify the logic that is executed when a certain command's invocation takes place.
Example 1: The IExecuteLogicMethods
Can-Execute Logic Methods
With the help of those methods you can identify whether a certain command can be executed or not.
Example 2: The ICanExecuteLogicMethods
A runnable demo that utilizes the code from this article can be found on the DataForm's CustomCommandsProvider demo.
Designing a Custom DataFormCommandProvider
The first step is to create your own class that inherits from DataFormCommandProvider:
Example 3: Defining a Custom CommandProvider
You need to override the methods of the commands that will be customized. In the following example we will customize: MoveCurrentToNext, MoveCurrentToPrevious, BeginEdit and CancelEdit.
MoveCurrentToNext and MoveCurrentToPrevious
We aim at changing their execution logic, in order to start editing the item, as soon as it was set as a current one and bypass the logic in the same place. Here are the overridden methods:
Example 4: Customizing MoveCurrentToNext and MoveCurrentToPrevious
CommitEdit and CancelEdit
A common requirement for data form is to add confirmation message boxes when CRUD operations are executed. Here we will do a similar thing with the CommitEdit/CancelEdit commands.
Example 5: Customizing CommitEdit and CancelEdit
Setting the Custom DataFormCommandProvider
The last thing to be done is to set the CommandProvider property of the RadDataForm to the newly-created CustomKeyboardCommandProvider class:
Example 6: Set the CommandProvider Property
Example 6: Set the CommandProvider Property
Executing Commands Manually
Using the RadDataFormCommands class, you can set a sequence of commands to be performed one after another. So, for example, you may easily handle the click event of a button, move to the next item and put it in edit mode. However, when invoking the commands in such a manner a second parameter should be added, pointing out the target UI Element as shown in Exapmle 7.