如何更改Windows Phone应用程序中按钮的背景颜色?

发布于 2024-10-09 13:57:09 字数 267 浏览 0 评论 0原文

我正在用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌梦深 2024-10-16 13:57:09

从按钮本身的点击事件更改按钮的样式有一个问题。彼得在这里详细说明。

为什么我无法在单击事件上更改按钮的背景? - 彼得·托尔的博客

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

乞讨 2024-10-16 13:57:09

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

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

℉絮湮 2024-10-16 13:57:09

我也遇到了那个“简单”的问题。我没有使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文