在后面的代码中更改silverlight 5中按钮的背景颜色

在后面的代码中更改silverlight 5中按钮的背景颜色,第1张

概述我想点击它时改变按钮的背景颜色.使按钮从红色变为绿色到红色等… 但是,当我点击背景颜色时不会改变. 这是我尝试过的: button4.Background.SetValue(BackgroundProperty,new SolidColorBrush(Colors.Red)); -> catastrophic errorbutton4.SetValue(BackgroundProperty,n 我想点击它时改变按钮的背景颜色.使按钮从红色变为绿色到红色等…

但是,当我点击背景颜色时不会改变.

这是我尝试过的:

button4.Background.SetValue(BackgroundProperty,new SolIDcolorBrush(colors.Red)); -> catastrophic errorbutton4.SetValue(BackgroundProperty,new SolIDcolorBrush(colors.Red)); -> nothingbutton4.Background = new SolIDcolorBrush(colors.Red); -> nothing

第三种解决方案似乎是最令人瞩目但却行不通的.

解决方法 我在Silverlight 5中遇到了与UserControl相同的问题.

protected overrIDe voID OnMouseleftbuttonDown(MousebuttonEventArgs e){  base.OnMouseleftbuttonDown(e);  Background = new SolIDcolorBrush(colors.Black); //nothing}

但如果我命名主GrID网格并写下这些代码

protected overrIDe voID OnMouseleftbuttonDown(MousebuttonEventArgs e){  base.OnMouseleftbuttonDown(e);  grID.Background = new SolIDcolorBrush(colors.Black); //ok}

它有效,我不知道为什么.当我需要使用一些复杂的不透明效果时,我可能需要一些额外的矩形并设置它们的填充.这有点不方便.

总结

以上是内存溢出为你收集整理的在后面的代码中更改silverlight 5中按钮的背景颜色全部内容,希望文章能够帮你解决在后面的代码中更改silverlight 5中按钮的背景颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004759.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存