绑定到画笔的颜色
我正在尝试为路径的 Fill 属性设置动画。 到目前为止我所拥有的是一个运行良好的 ColorAnimation。 目标属性是 (Shape.Fill).(SolidColorBrush.Color),我将其设置为值“#999999”(只是示例颜色)。
问题来自于我想将值设置为“{TemplateBinding Background}”。 由于背景是画笔,而我的目标属性是颜色,这只会导致动画中没有颜色。
如果我能弄清楚如何将值设置为背景画笔的颜色部分,我会很高兴。 有任何想法吗?
顺便说一句,这是在 ToggleButton 的控件模板中。
谢谢, 大卫
I am trying to animate the Fill property of a path. What I have so far is a ColorAnimation that works well. The target property is (Shape.Fill).(SolidColorBrush.Color) and I set it to a value of "#999999" (just an example color).
The problem comes from the fact that I'd like to set the value to "{TemplateBinding Background}". Since Background is a brush and the property I'm targeting is a color this just results in no color in the animation.
I would be happy if I could just figure out how to set the value to the color portion of the background brush. Any ideas?
BTW, this is in a control template for a ToggleButton.
Thanks,
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个实现 IValueConverter 的类,并将其设置为绑定的
Converter
属性。 您仍然需要将绑定设置为Background
,但这又会传递给您的转换器。 转换器可以从画笔中提取颜色,然后将其返回。You could create a class that implements IValueConverter, and set this as the
Converter
property of the binding. You would still set the binding to theBackground
, but that would in turn be passed to your converter. The converter can extract the color from the brush, and then return that.