3
votes

I am developing window phone 7 application in C# & silverlight 4. I am new to the silverlight.I have two buttons in my application for different purposes. I want to change the color of the button dynamically when the button gets clicked. So I am using the following code

 IncomeButton.Background = new SolidColorBrush(Colors.Red);

But it is not working. Can you please provide me any code or link through which I can resolve the above issue ? If I am doing anything wrong then please guide me.

3

3 Answers

4
votes

Changing the styling of a button from it's own click event comes with a catch. Peter elaborates here.

Why can't I change the Background of my Button on a Click event? - Peter Torr's Blog

2
votes

You can simply execute IncomeButton.UpdateLayout() after changing button's color.

1
votes

I also ran into that "simple" problem. Instead of using Peter's "button styling change" thing, I simply placed a rectangle below the button and changed it's color with the Rectangle.Fill property in the Click event of the button. Works fine for me.