Commands

RadCheckBox exposes a Commands collection that allows you to register custom commands with each control’s instance through the Commands property:

  • Commands: Gets the collection with all the custom commands registered with the CommandService.

Command Type

There are two types of commands:

  • CheckBoxCommand: All the default commands within RadCheckBox derive from the base RadCheckBoxCommand. Think of this command as a UI-related command as it operates over the RadCheckBox instance that owns the command.
  • CheckBoxUserCommand: This type of command should be used when you would like to modify the behavior of the control on any of the available actions. It exposes the following properties:
    • Id: The key that relates a command instance to a particular action/routine.
    • Command: Gets or sets the generic ICommand implementation.
    • SuppressDefaultCommand: Gets or sets a value indicating whether the default(built-in) UI command associated with the specified Id will be executed.

Example

Here is an example how to create a CheckBoxUserCommand.

Add the RadCheckBox control and bound the IsCheckedChangedCommand through the CheckBoxUserCommand predefined command. Use the Id property to map the command to the corresponding action with the control. In the following example we set the Id property to the IsCheckedChanged CommandId Enumaration.

<telerikPrimitives:RadCheckBox x:Name="checkbox">
    <telerikPrimitives:RadCheckBox.Commands>
        <checkBoxComamnds:CheckBoxUserCommand Command="{Binding IsCheckedChangedCommand}" Id="IsCheckedChanged" SuppressDefaultCommand="True"/>
    </telerikPrimitives:RadCheckBox.Commands>
</telerikPrimitives:RadCheckBox>
<Label x:Name="label"/>

use the following namespace:

    xmlns:checkBoxComamnds="clr-namespace:Telerik.XamarinForms.Primitives.CheckBox.Commands;assembly=Telerik.XamarinForms.Primitives"

And lets directly handle the needed command in the class and create methods for CanExecute and Execute the IsCheckedChangedCommand.

Here is a quick example:

public ICommand IsCheckedChangedCommand { get; set; }
public CheckBoxCommands()
{
    this.IsCheckedChangedCommand = new Command((p) => IsCheckedChangedCommandExecute(p), (p) => IsCheckedChangedCommandCanExecute(p));
    this.BindingContext = this;
    InitializeComponent();
}
private bool IsCheckedChangedCommandCanExecute(object p)
{
    return true;
}
private void IsCheckedChangedCommandExecute(object p)
{
    this.label.Text = "CheckBox User Command executed at " + DateTime.Now.ToLocalTime();
}

See Also

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy