Using C# and Visual Studio 2010, how can I change the background color of a button once another button is pressed? Am I not including a System.? wrong?
What I have at the moment is:
ButtonToday.Background = Color.Red;
And it's not working.
Using C# and Visual Studio 2010, how can I change the background color of a button once another button is pressed? Am I not including a System.? wrong?
What I have at the moment is:
ButtonToday.Background = Color.Red;
And it's not working.
I doubt if any of those should work. Try: First import the namespace in the beginning of the code page as below.
then in the code.
Hope it helps.
I had trouble at first with setting the colors for a WPF applications controls. It appears it does not include
System.Windows.Media
by default but does includeWindows.UI.Xaml.Media
, which has some pre-filled colors.I ended up using the following line of code to get it to work:
You should be able to change
grid.Background
to most other controls and then changeCadetBlue
to any of the other colors it provides.WinForm:
WPF:
In WPF, the background is not a
Color
, it is aBrush
. So, try this for starters:More sensibly, though, you should probably look at doing this in your Xaml instead of in code.
Code for set background color, for
SolidColor
: