简体   繁体   English

DataTrigger WPF上的BeginStorybard

[英]BeginStorybard on DataTrigger WPF

I am using a transition animation for when my application boots up. 我在应用程序启动时使用过渡动画。

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

This works well if I start it as an EventTrigger RoutedEvent="FrameworkElement.Loaded" But I want to bind it to a property on my viewModel called IsInitialized . 如果我将其作为EventTrigger RoutedEvent="FrameworkElement.Loaded"启动,则效果很好,但我想将其绑定到viewModel上名为IsInitialized的属性。 Problem is Windows.Triggers doesn't allow DataTrigger . 问题是Windows.Triggers不允许DataTrigger

How can I do that? 我怎样才能做到这一点?

You are correct that you cannot use a DataTrigger in your Triggers collection. 您是正确的,您不能在Triggers集合中使用DataTrigger Instead, you need to use the UIElement.Style.Triggers collection. 相反,您需要使用UIElement.Style.Triggers集合。 Then you can use the DataTrigger.EnterActions element to host your Storyboard element: 然后,您可以使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM