我在应用程序启动时使用过渡动画。
<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
。我怎样才能做到这一点?
最佳答案
您是正确的,您不能在DataTrigger
集合中使用Triggers
。相反,您需要使用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>
关于c# - DataTrigger WPF上的BeginStorybard,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22409177/