SolidColorBrush在运行时更改颜色 [英] SolidColorBrush color change at runtime
本文介绍了SolidColorBrush在运行时更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序资源文件刷:
< SolidColorBrush x:Key =MainColorColor = FF15428B/>
我想在运行时更改此画笔的颜色。我添加了颜色选择器 - 当用户选择颜色我想让这个画笔选择颜色。
我尝试过这样的代码:
SolidColorBrush MainColor = new SolidColorBrush (SelectedColor);
但它没有工作。
解决方案
您需要设置现有画笔颜色
属性
您可以通过写(SolidColorBrush)Resources [MainColor]
/ p>
I have in my application resources file brush:
<SolidColorBrush x:Key="MainColor" Color="#FF15428B" />
I want to change color of this brush at runtime. I added color picker - when user choose color I want this brush to have selected color.
I tried code like that:
SolidColorBrush MainColor = new SolidColorBrush(SelectedColor);
But it didn't work.
解决方案
You need to set the existing brush's Color
property.
You can get the instance by writing (SolidColorBrush)Resources["MainColor"]
这篇关于SolidColorBrush在运行时更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文