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.

Was it helpful?

Solution 3

var eelement = gridMain.Children
                       .OfType<Button>()
                       .Where(b => vb.Name.Equals(_buttonName))
                       .FirstOrDefault();
eelement.Background = Brushes.Yellow; 

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top