How to Use Toggle Button: WPF

September 12, 2013 , , , 0 Comments

Toggle button is a sticky button, which have two states i.e. checked and Unchecked by default. It don’t have cancel behaviours of the button. Clicking this first time will set IsChecked property to true, and second time clicking will set IsChecked property to false.

The following XAML code will show two toggle buttons with IsChecked property true and false respectively. As the checkbox button, toggle button also have IsThreeState property means it have three states i.e. checked, unchecked and indeterminate.

<ToggleButton Margin="5" Height="20" Width="100" IsChecked="True"/>
<ToggleButton Margin="5" Height="20" Width="100" IsChecked="False"/>

When we want to use the third state, then the value of IsChecked will be {x:Null} and it will also look like false value. The above code will show the window with two toggle button like following image:

To use third property we have to set IsThreeState property to true. Now first click set the IsChecked to true, second will set null and third will set to false. It have individual event for all the three states:
private void ToggleButton_Checked(object sender, RoutedEventArgs e)

private void toggleButton_Unchecked(object sender, RoutedEventArgs e)

private void toggleButton_Indeterminate(object sender, RoutedEventArgs e)

Subhash Sharma

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google