RadControls for WPF

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.
Tip
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.

CopyC#
public class SampleViewModel
{
   public SampleViewModel()
   {
   }
   public ICommand MyCommand
   {
       get;
       set;
   }
}
CopyVB.NET
Public Class SampleViewModel
 Public Sub New()
 End Sub
 Public Property MyCommand() As ICommand
  Get
  End Get
  Set
  End Set
 End Property
End Class

Set the SampleViewModel as the DataContext of your UserControl.

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

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

Note

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"

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

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

See Also

Other Resources