给定:控制(x:名称=" border1"),VisualStateManager
。控件的RenderTransform
设置为TransformGroup
,其中包含TranslateTransform
。
在VisualState
" NotShown"中,TranslateTransform
s Y
属性应设置为Value
的动画,该ClipToBounds
是(至少)高度的<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>
控制被翻译(有效地使其不可见 - {Binding ActualHeight, ElementName=border1}
设置为真)。
这是Blend生成的代码:
{{1}}
编辑(2):{{1}}根本不起作用。当从VS而不是Blend运行时,有一个提示:
无法找到管理FrameworkElement或FrameworkContentElement 目标要素。 BindingExpression:路径=的ActualHeight;的DataItem = NULL; 目标元素是&#39; EasingDoubleKeyFrame&#39; (的HashCode = 57957548);目标 财产是&#39;价值&#39; (键入&#39; Double&#39;)
如何为此动画的目的正确设置内容?
答案 0 :(得分:0)
TemplateBinding
而不是Binding
。Binding
/ TemplateBinding
仅在FrameworkElement
上“有效”(EasingDoubleKeyFrame
为DependencyObject
,而不是FrameworkElement
。所以你必须在代码隐藏中做动画。