[英]BeginStorybard on DataTrigger WPF
我在应用程序启动时使用过渡动画。
<Storyboard x:Key="InTransition">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:05.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-72"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="-157"/>
<SplineDoubleKeyFrame KeySpline="0.5,0,0.5,1" KeyTime="00:00:05.5000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
如果我将其作为EventTrigger RoutedEvent="FrameworkElement.Loaded"
启动,则效果很好,但我想将其绑定到viewModel上名为IsInitialized
的属性。 问题是Windows.Triggers
不允许DataTrigger
。
我怎样才能做到这一点?
您是正确的,您不能在Triggers
集合中使用DataTrigger
。 相反,您需要使用UIElement.Style.Triggers
集合。 然后,您可以使用DataTrigger.EnterActions
元素来托管Storyboard
元素:
<Window ...>
<Window.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding YourProperty}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard ... />
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Style>
</Window>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.