Animation Dependency Properties

I have a custom control that registers 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); }
    }
    ...

      

I am using this property to calculate Margins

some of the child controls in combination with IValueConverter

.

On a page using this control, I create Storyboard

which should animate a property HoverHeight

:

<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>

      

The storyboard contains other animations that work as expected. However, when I run the storyboard, the value HoverHeight

doesn't change. Neither the handler OnHoverHeightChanged

nor the converter is called with the new value. I can set a new value using the property setter, which in turn calls the handler OnHoverHeightChanged

, so there is probably an animation issue.

No exit or exception is thrown when the storyboard is run.

Am I missing something? How can I animate a custom dependency property?

+3


source to share


1 answer


Set the animation property EnableDependentAnimation to True.



Dependent animations don't start at all in Windows 8 by default. By default, they are independent animations (such as animations that perform GPU transformations), so you won't be able to get notified of the change on the UI thread. At least that's my understanding.

+9


source







All Articles