如何更改Windows Phone应用程序中按钮的背景颜色?
我正在用 C# 和 C# 开发 Windows Phone 7 应用程序。 silverlight 4. 我是 silverlight 的新手。我的应用程序中有两个用于不同目的的按钮。我想在单击按钮时动态更改按钮的颜色。所以我使用下面的代码
IncomeButton.Background = new SolidColorBrush(Colors.Red);
但它不起作用。您能给我提供任何可以解决上述问题的代码或链接吗?如果我做错了什么,请指导我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从按钮本身的点击事件更改按钮的样式有一个问题。彼得在这里详细说明。
为什么我无法在单击事件上更改按钮的背景? - 彼得·托尔的博客
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()
即可。You can simply execute
IncomeButton.UpdateLayout()
after changing button's color.我也遇到了那个“简单”的问题。我没有使用 Peter 的“按钮样式更改”,而是简单地在按钮下方放置了一个矩形,并使用按钮的 Click 事件中的 Rectangle.Fill 属性更改了它的颜色。对我来说效果很好。
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.