Commands
RadCollectionEditor
provides a set of built-in commands that enables you to handle the user interface actions, but still make your logic independent of the UI layout.
All supported commands are defined in the CollectionEditorCommands
class and are listed below.
AddNew
Delete
MoveCurrentToNext
MoveCurrentToPrevious
Using the CollectionEditorCommands
To utilize the built-in CollectionEditor commands, you can set them directly to the Command
property of a button. Once you click the button, the predefined command will be executed.
Binding a CollectionEditorCommands.Delete command in XAML
<StackPanel>
<telerikControls:RadCollectionEditor x:Name="collectionEditor"/>
<telerikControls:RadButton Content="Delete"
Command="{x:Bind telerikControls:CollectionEditorCommands.Delete}"
CommandTarget="{x:Bind collectionEditor}"/>
</StackPanel>
Custom CommandProvider
RadCollectionEditor
exposes a CommandProvider
property that allows you to customize the behavior of the commands in an MVVM-friendly way. Each of the commands listed in the beginning of the article can be customized by overriding its corresponding Execute
/CanExecute
method of the default CollectionEditorCommandProvider
.
Creating a custom CollectionEditorCommandProvider
public class CustomCommandProvider : CollectionEditorCommandProvider
{
public override async void Delete()
{
ContentDialog contentDialog = new ContentDialog()
{
Title = "Delete confirmation",
Content = "Are you sure?",
PrimaryButtonText = "Delete",
SecondaryButtonText = "Cancel"
};
contentDialog.XamlRoot = this.CollectionNavigator.XamlRoot;
ContentDialogResult result = await contentDialog.ShowAsync();
if (result == ContentDialogResult.Secondary)
{
//cancel deletion
}
else
{
base.Delete();
}
}
}
RadCollectionEditor with custom CommandProvider implementation
<Grid>
<Grid.Resources>
<local:CustomCommandProvider x:Key="CustomCommandProvider"/>
</Grid.Resources>
<telerikControls:RadCollectionEditor x:Name="collectionEditor" CommandProvider="{StaticResource CustomCommandProvider}"/>
</Grid>