Commands

The RadButtons provide you with a standard ICommandSource implementation. This means that you can bind your buttons to commands that will be executed when the button is clicked. In order to take advantage of the ICommandSource implementation you can use the following properties:

  • Command - gets the command that will be executed when the command source is invoked.

  • CommandParameter - represents a user defined data value that can be passed to the command when it is executed.

  • CommandTarget - the object on which the command is being executed.

As the RadButtons implement the ICommandSource, you can use them with any command that implements the ICommand interface, for example Telerik DelegateCommand.

Example

Here is an example of a command usage in a MVVM scenario. The command is located in the SampleViewModel class.

Example 1: Defining a command

public class SampleViewModel 
{ 
   public SampleViewModel() 
   { 
   } 
   public ICommand MyCommand 
   { 
       get; 
       set; 
   } 
} 
Public Class SampleViewModel 
    Public Sub New() 
    End Sub 
    Public Property MyCommand() As ICommand 
        Get 
            Return m_MyCommand 
        End Get 
        Set(value As ICommand) 
            m_MyCommand = Value 
        End Set 
    End Property 
    Private m_MyCommand As ICommand 
End Class 

Set the SampleViewModel as the DataContext of your UserControl.

Example 2: Setting up the DataContext

public Example() 
{ 
    InitializeComponent(); 
    this.DataContext = new SampleViewModel(); 
} 
Public Sub New() 
    InitializeComponent() 
    Me.DataContext = New SampleViewModel() 
End Sub 

In the XAML provide the bindings for the command and set the command parameter.

RadButtons are located in the Telerik.Windows.Controls.dll and in order to use them in your project you have to add a reference to the assembly. You can find more info here.

Then in XAML you have to declare the namespace: xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

Example 3: Setting up the Command and CommandParameter properties

<telerik:RadButton Content="My Button" 
                   Command="{Binding MyCommand}" 
                   CommandParameter="ParameterValue" /> 

This is a very basic sample, but you can apply this approach to any type of commands that implement the ICommand interface.

See Also

In this article
Not finding the help you need? Improve this article