使用 StaticResource SolidColorBrush 定义渐变停止颜色
我正在创建一些 wpf 资源字典,其中包含应用程序的所有样式!我有一些 LinearGradientBrush
es,其中颜色直接在 LinearGradientBrush
引用中设置为 GradientStop
s。但是,我希望有一组预定义的颜色,可以为每个 GradientStop
使用参考,因此更改应用程序的颜色方案只需更改 SolidColorBrush 的值即可
es:
<SolidColorBrush Color="#5A5A5A" x:Key="colorbrushMedium" />
<SolidColorBrush Color="#222222" x:Key="colorbrushDark" />
<LinearGradientBrush>
<GradientStop Color="{StaticResource colorbrushMedium}"/>
<GradientStop Color="{StaticResource colorbrushDark}" Offset="1"/>
</LinearGradientBrush>
通过上面的代码示例,我收到以下错误:
Cannot convert the value in attribute 'Color' to object of type 'System.Windows.Media.Color'. '#5A5A5A' is not a valid value for property 'Color'.
它引用的行是
所在的行定义的。
有什么想法吗?
I am creating some wpf resource dictionaries with all the styles for an application! I have a few LinearGradientBrush
es, where the color is set directly in the LinearGradientBrush
reference as GradientStop
s. However, I want to have a predefined set of colors that I can use a a reference for each GradientStop
, so that changing the color scheme for the application is a matter of changing the values of the SolidColorBrush
es:
<SolidColorBrush Color="#5A5A5A" x:Key="colorbrushMedium" />
<SolidColorBrush Color="#222222" x:Key="colorbrushDark" />
<LinearGradientBrush>
<GradientStop Color="{StaticResource colorbrushMedium}"/>
<GradientStop Color="{StaticResource colorbrushDark}" Offset="1"/>
</LinearGradientBrush>
With the code example above, I am getting the following error:
Cannot convert the value in attribute 'Color' to object of type 'System.Windows.Media.Color'. '#5A5A5A' is not a valid value for property 'Color'.
The line it refers to is the line where <GradientStop Color="{StaticResource colorbrushMedium}"/>
is defined.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我发现了问题:
使用 Color 而不是 SolidColorBrush..
这似乎解决了我的问题!
Ok, I found the problem:
Using Color and not SolidColorBrush..
This seems to solve my problem!
使用
Binding
引用SolidColorBrush
和LinearGradientBrush
中的颜色:Use
Binding
to reference the color both inSolidColorBrush
and inLinearGradientBrush
: