如何在 Silverlight 中绑定 GradientStop 颜色或 GradientStops 属性? [英] How to bind GradientStop Colours or GradientStops Property in Silverlight?

查看:18
本文介绍了如何在 Silverlight 中绑定 GradientStop 颜色或 GradientStops 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在 Silverlight 中拥有动态渐变,如下所示:

I want to be able to have a dynamic Gradient in Silverlight, such as below:

<RadialGradientBrush GradientOrigin="0.20,0.5" Center="0.25,0.50" 
                     RadiusX="0.75" RadiusY="0.5">
  <GradientStop Color="{Binding Path=GradientStart}" Offset="0" />
  <GradientStop Color="{Binding Path=GradientEnd}" Offset="1" />
</RadialGradientBrush>

我绑定到两个返回颜色"类型的属性,但是我总是收到此消息:

I am binding to two properties which return the type "Color" however I always get this message:

AG_E_PARSER_BAD_PROPERTY_VALUE

如果我尝试绑定到 GradientStop 集合,这也有同样的问题,这个问题的解决方案是什么:

If I try to bind to a GradientStop Collection this also has the same problem, what is the solution to this problem that:

  1. 允许在运行时更改渐变的开始和结束
  2. 适用于 Silverlight 3.0,不是 WPF 解决方案

如果有解决方法或无论如何要复制这种行为,这是可以接受的,我有使用 LinearGradients 的解决方案,因为我可以将某些填充"属性绑定到此 - 但是在这种情况下不起作用,此外,我可能会使用其他渐变类型,并且其他人可能会在未来使用此解决方案/替代方案将适用于这些渐变类型.

If there is a work around or anyway to duplicate this behaviour this would be acceptable, I have solutions that work with LinearGradients as I can just bind somethings "Fill" property to this - however in this situation that won't work, plus there may be other gradient types I may use and others may use in future which this solution / alternative will apply to.

推荐答案

问题在于 GradientStop 不是从 FrameworkElement 派生的,因此无法进行数据绑定.不幸的是,这意味着您必须从代码中进行设置.

The problem is that GradientStop does not derive from FrameworkElement therefore cannot be data bound. Unfortunately that means you have to set it from code.

这篇关于如何在 Silverlight 中绑定 GradientStop 颜色或 GradientStops 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆