简体   繁体   中英

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

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.

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

更改按钮的颜色后,您只需执行IncomeButton.UpdateLayout()即可。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM