Click here to Skip to main content
14,971,209 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want to change backcolor of toggle button when toggle button ischecked and viceversa in WPF.
According to togglr button's checked mode i need to change the color
Updated 10-Apr-11 23:04pm

You have to use two events : Checked and Unchecked.

Do it like this :

public Window1()
    this.Loaded += new RoutedEventHandler(Window1_Loaded);
    toggleButton.Checked += new RoutedEventHandler(toggleButton_Checked);
    toggleButton.Unchecked += new RoutedEventHandler(toggleButton_Unchecked);

        private void toggleButton_Checked(object sender, RoutedEventArgs e)
            ToggleButton button = (ToggleButton)sender;
            button.Background = Brushes.Aqua;

        private void toggleButton_Unchecked(object sender, RoutedEventArgs e)
            ToggleButton button = (ToggleButton)sender;
            button.Background = Brushes.Red;

Now it should work!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900