绑定到画笔的颜色

发布于 2024-07-27 17:58:53 字数 338 浏览 1 评论 0原文

我正在尝试为路径的 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 技术交流群。

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

发布评论

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

评论(1

甩你一脸翔 2024-08-03 17:58:53

您可以创建一个实现 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 the Background, but that would in turn be passed to your converter. The converter can extract the color from the brush, and then return that.

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