4

Given: Control (x:Name="border1") with a VisualStateManager. Control's RenderTransform is set to a TransformGroup that contains a TranslateTransform.

In VisualState "NotShown", TranslateTransforms Y property should be animated to a Value that is (at least) the height of the control being translated (effectively rendering it invisible - ClipToBounds set true).

This is the code Blend generates:

<VisualState x:Name="NotShown">
    <Storyboard>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="border1">
            <EasingDoubleKeyFrame KeyTime="0" Value="{Binding ActualHeight, ElementName=border1}"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

EDIT (2): {Binding ActualHeight, ElementName=border1}does not work at all. When run from VS instead of Blend, there is a hint:

Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ActualHeight; DataItem=null; target element is 'EasingDoubleKeyFrame' (HashCode=57957548); target property is 'Value' (type 'Double')

How do I properly set things up for the purpose of this animation?

1 Answers1

0
  1. You are in the ControlTemplate, so you have to use TemplateBinding instead of Binding.
  2. Binding/TemplateBinding only "works" on FrameworkElement (EasingDoubleKeyFrame is a DependencyObject, not a FrameworkElement). So you have to do your animation in code-behind.
Nicolas Voron
  • 2,916
  • 1
  • 21
  • 35