var eelement = gridMain.Children
.OfType<Button>()
.Where(b => vb.Name.Equals(_buttonName))
.FirstOrDefault();
eelement.Background = Brushes.Yellow;
How do I change dynamically a background color of a WPF:s button [duplicate]
-
19-07-2023 - |
Question
Goal:
Change dynamically the button's background color inside of my customized private function. The start point is
gridMain.Children.
Problem:
I tried googling and I read about class button and lots of different website but I cannot find a relevant clue in order to change the background color. My way of thinking is that the concept will be same as nhibernate's ability to edit data and then save it.
I need to retrieve a specific button from gridMain.Children.
that has a name, btn_test, and change the background color and then to be saved.
Again, the problem is that I cannot find a relevant code to my purpose.
Info:
- I'm using VS 2013 with WPF and C#.
- Inside of gridMain.Children. I have a lot of button with different name. Buttons are created dynamically.
Solution 3
OTHER TIPS
Button1.Background = new SolidColorBrush(Colors.Red);
courtesy: Dan Puzey (From his answer to this question)
button.Background = Brushes.Blue;
The WPF Button class has Background property, which needs to be set as a Brush.