How to change the background color of button in windows phone application?

16,819

Solution 1

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

Solution 2

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

Solution 3

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.

Share:
16,819
Shailesh Jaiswal
Author by

Shailesh Jaiswal

Updated on June 04, 2022

Comments

  • Shailesh Jaiswal
    Shailesh Jaiswal almost 2 years

    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.