Edit this page

Toggle Button

RadToggleButton inherits from the native ToggleButton control and implements the ICommandSource interface. Because of the inheritance, it has all of the features of the native ToggleButton control has. The ICommandSource implementation allows you to attach commands to the button, which will get executed when it gets clicked.

To learn more about the members of the RadToggleButton class you can read here.

You can see how to use ICommand with a button in the Commands topic.

Instantiating RadToggleButton

You can instantiate RadToggleButton in both XAML and code. Here is an example:

RadToggleButton is located in the Telerik.Windows.Controls.dll and in order to use it 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"

[XAML] Example 1: Defining a button in XAML

<telerik:RadToggleButton Content="Toggle Me!" />

[C#] Example 2: Defining a button in code

RadToggleButton radToggleButton = new RadToggleButton();

[VB.NET] Example 2: Defining a button in code

Dim radToggleButton As New RadToggleButton()

Handling the Button Checked Event

To execute some logic when RadToggleButton gets toggled, you have to handle the Checked event.

As any other button RadToggleButton exposes a Click event, too.

Here is an example of handling the Checked event of a button.

[XAML] Example 3: Subscribing to the Checked event

<telerik:RadToggleButton Content="Toggle Me!" Checked="RadToggleButton_Checked" />

[C#] Example 4: Defining a Checked event handler

private void RadToggleButton_Checked(object sender, RoutedEventArgs e)
{
    //implement your logic here
}

[VB.NET] Example 4: Defining a Checked event handler

Private Sub RadToggleButton_Checked(sender As Object, e As RoutedEventArgs)
    'implement your logic here'
End Sub

RadToggleButton also exposes Unchecked event that is called when the button is unchecked. The same handling (as with the Checked event) applies for the Unchecked event.

Three State RadToggleButton

To make RadToggleButton to go into a three state mode you just have to set its IsThreeState property to True. Here is an example:

[XAML] Example 5: Enabling the three-state mode

<telerik:RadToggleButton IsThreeState="True" />

Customizing RadToggleButton

  • IsBackgroundVisible: this property controls the visibility of the background and the border of RadToggleButton in normal state

  • CornerRadius: this property controls the CornerRadius of RadToggleButton

See Also