与绑定属性故事板(自定义控件:动画颜色变化) [英] Storyboards with bound properties (custom control: animate colour change)

查看:161
本文介绍了与绑定属性故事板(自定义控件:动画颜色变化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要简单地说,我有这样的 ControlTemplate.Triggers 状况 EnterAction 中:

To put it simply, I have this within a ControlTemplate.Triggers condition EnterAction:

<ColorAnimation To="#fe7" Storyboard.TargetProperty="Background.Color" Duration="00:00:00.1" Storyboard.TargetName="brd"/>

不过,我想'到'颜色(#fe7 )是定制的。这是从的ListBox 派生的控件。我可以创建一个的DependencyProperty ,但当然,我不能绑定的属性 ColorAnimation 来它,因为故事板已被冻结,你不能用绑定的东西冻结(据我所知)。

But I want the 'to' colour (#fe7) to be customisable. This is a control derived from ListBox. I can create a DependencyProperty, but of course, I cannot bind the To property of the ColorAnimation to it because the Storyboard has to be frozen and you can't freeze something with bindings (as I understand it).

我试图用一个 {StaticResource的} ,然后填充在code中的资源-behind当的DependencyProperty 被改变,通过设置 this.Resources [ItemColour] =为newValue; 的实例。没有工作也许很明显,这是一个静态的资源毕竟:没有新的属性值被拾起。 DynamicResource 给有关无法冻结了同样的问题。

I tried using a {StaticResource} within the To, then populating the resource in the code-behind when the DependencyProperty was changed, by setting this.Resources["ItemColour"] = newValue; for instance. That didn't work perhaps obviously, it's a static resource after all: no new property values were picked up. DynamicResource gave the same problem relating to inability to freeze.

属性只能设置一次创建控件的时候,我不担心它改变中期的动画。

The property is only set once when the control is created, I don't have to worry about it changing mid-animation.

是否有这样做的一个很好的方式吗?我必须求助于寻找属性更改自己,动态调用,并在该点管理故事板?或覆盖控制的两个版本,开始和结束的颜色,不透明度动画代替?双方似乎可笑..

Is there a nice way of doing this? Do I have to resort to looking for property changes myself, dynamically invoking and managing storyboards at that point? Or overlaying two versions of the control, start and end colour, and animating Opacity instead? Both seem ludicrous..

推荐答案

原来这根本是不可能的。

It turns out this is simply not possible.

这篇关于与绑定属性故事板(自定义控件:动画颜色变化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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