Home » WPF ToggleButton Control

WPF ToggleButton Control

by Online Tutorials Library

WPF ToggleButton Control

Toggle Button is known as a control with the help of which we can move from one state to another state. CheckBox and RadioButton are an example of the Toggle Button.

Here we are going to take an example of the ToggleButton Control. In this example, we will change the text of the toggle button after clicking on this button. That is why the toggle button shows the current state.

For the toggle button, we can use trigger property, which we will use to fire when the property of the IsChecked is changed.

The XAML code for the ToggleButton control is given below:

The output of the above code before clicking on the toggle button will look like as shown in the below screenshot:

Output

WPF ToggleButton Control

Now when we click on the toggle button, the text will change and the output of the above code will look like as shown in the below screenshot:

OUTPUT

WPF ToggleButton Control

Now we will take another example of the ToggleButton

Now we will write the XAML code to create and initialize the togglebutton with some properties.

MainWindow.XAML

Here is the C# implementation of the checked and unchecked events.

MainWindow.XAML.cs

When we compile and execute the above code, after the execution of the code, the output will look like as shown in the below screenshot:

OUTPUT

WPF ToggleButton Control


You may also like