一 背景颜色
这里以按钮为例:
1、设置背景颜色
//通过包装的属性设置按钮的背景颜色
btn_ButtonC.Background = new SolidColorBrush(Colors.Red);
或者 menujbsz.Background = new SolidColorBrush(Color.FromArgb(47,0,255,255));
// 通过依赖性属性的SetValue设置按钮的背景颜色
SolidColorBrush brush = new SolidColorBrush(Colors.Blue);
btn_ButtonD.SetValue(
Button.BackgroundProperty, brush);
2、获取背景颜色
// 通过包装的属性获取ButtonB的背景颜色
SolidColorBrush b_Brush1 = (SolidColorBrush) (btn_ButtonB.Background);
txt_Value1.Text = b_Brush1.Color.ToString();
// 通过依赖性属性的 GetValue获取ButtonB的背景颜色
SolidColorBrush b_Brush2 = (SolidColorBrush) (btn_ButtonB.GetValue(
Button.BackgroundProperty));
txt_Value2.Text = b_Brush2.Color.ToString();
本文介绍了如何使用WPF设置按钮的背景颜色,并提供了两种设置方法:一是通过包装属性设置;二是通过依赖性属性的SetValue方法设置。此外,还介绍了如何获取按钮的背景颜色。
9008

被折叠的 条评论
为什么被折叠?



