动画依赖属性 [英] Animate dependency properties

查看:114
本文介绍了动画依赖属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有registrates依赖项属性 HoverHeight 自定义用户控件:

I have a custom user control that registrates a dependency property HoverHeight:

public sealed partial class VirtualPointer : UserControl
{
    public static readonly DependencyProperty HoverHeightProperty =
         DependencyProperty.Register("HoverHeight", typeof(double),
         typeof(VirtualPointer), new PropertyMetadata(1.0,OnHoverHeightChanged));

    public double HoverHeight
    {
        get { return (double)GetValue(HoverHeightProperty); }
        set { SetValue(HoverHeightProperty, value); }
    }
    ...



我使用这个属性来计算<结合一些子控件code>页边距与按的IValueConverter

在使用该控件的页面,我创建了一个故事板这应该动画 HoverHeight 属性:

In a page that uses this control, I create a Storyboard which should animate the HoverHeight property:

<Page ...>
    <Page.Resources>
        <Storyboard>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="virtualPointer" Storyboard.TargetProperty="HoverHeight">
                <LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:0"/>
                <LinearDoubleKeyFrame Value="0.0" KeyTime="0:0:1"/>
                <LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:2"/>
                <LinearDoubleKeyFrame Value="0.0" KeyTime="0:0:3"/>
                <LinearDoubleKeyFrame Value="1.0" KeyTime="0:0:4"/>
            </DoubleAnimationUsingKeyFrames>
            <!-- other DoubleAnimationUsingKeyFrames -->
        </Storyboard>
    </Page.Resources>
    <!-- ... -->
    <local:VirtualPointer Name="virtualPointer" HoverHeight="0.5"/>    
</Page>



,故事情节包含的工作如预期其他动画。然而,当我开始在故事板 HoverHeight 值不会改变。无论是 OnHoverHeightChanged 处理程序被调用,也不与新价值的转换器。我可以设置属性setter这反过来又调用 OnHoverHeightChanged 处理新的价值,所以有可能是与动画有问题。

The storyboard contains other animations which work as expected. However, when I start the storyboard the HoverHeight value does not change. Neither the OnHoverHeightChanged handler is called, nor the converter with the new value. I can set a new value with the property setter which in turn calls the OnHoverHeightChanged handler, so there is probably a problem with the animation.

有没有开始的故事板时产生的输出或异常。

There is no output or exception generated when starting the storyboard.

我失去了一些东西在这里?我怎样才能动画自定义依赖属性?

Am I missing something here? How can I animate the custom dependency property?

推荐答案

动画的EnableDependentAnimation属性设置为True。

Set the animation's EnableDependentAnimation property to True.

相关动画默认情况下不运行在Windows 8上的。默认情况下,他们是独立的动画(如它们执行GPU转换动画),所以你将无法接收UI线程上的更改通知。至少这是我的理解。

Dependent animations don't run at all on Windows 8 by default. By default, they are independent animations (such as animations which perform GPU transforms), so you will not be able to receive the change notification on the UI thread. At least that's my understanding.

这篇关于动画依赖属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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