WPF Toggle Button Checked/Uchecked event with one handler

后端 未结 3 925
逝去的感伤
逝去的感伤 2021-02-18 21:27

I am using a ToggleButton in a WPF window:

 

        
3条回答
  •  孤街浪徒
    2021-02-18 22:19

    You can attach a single click event of your ToggleButton and in its handler you can check the ToggleButton IsChecked property by type casting the sender object in your handler like this -

    private void ToggleButton_Click(object sender, RoutedEventArgs e)
    {
       if((sender as ToggleButton).IsChecked)
       {
          // Code for Checked state
       }
       else
       {
          // Code for Un-Checked state
       }
    }
    

    Xaml:

    Timeout
    

提交回复
热议问题