C# Change A Button's Background Color

前端 未结 7 946
独厮守ぢ
独厮守ぢ 2020-12-01 14:04

How can the background color of a button once another button is pressed?

What I have at the moment is:

ButtonToday.Background = Color.Red;
         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 14:23

    In WPF, the background is not a Color, it is a Brush. So, try this for starters:

    using System.Windows.Media;
    
    // ....
    
    ButtonToday.Background = new SolidColorBrush(Colors.Red);
    

    More sensibly, though, you should probably look at doing this in your Xaml instead of in code.

提交回复
热议问题