我想在选中切换按钮时更改切换按钮的背景色,反之亦然. [英] i want to change backcolor of toggle button when toggle button ischecked and viceversa in WPF.
本文介绍了我想在选中切换按钮时更改切换按钮的背景色,反之亦然.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在选中切换按钮时更改切换按钮的背景色,反之亦然.在WPF中,我想更改切换按钮的背景色.
根据togglr按钮的选中模式,我需要更改颜色
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
推荐答案
您必须使用两个事件:Checked
和Unchecked
.
这样做:
You have to use two events :Checked
andUnchecked
.
Do it like this :
public Window1()
{
InitializeComponent();
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!
此链接将帮助您...
http://www.c- sharpcorner.com/Resources/702/how-to-set-background-color-of-a-wpf-button.aspx [
This link will help you...
http://www.c-sharpcorner.com/Resources/702/how-to-set-background-color-of-a-wpf-button.aspx[^]
这篇关于我想在选中切换按钮时更改切换按钮的背景色,反之亦然.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文