1

当我的应用程序启动时,我正在使用过渡动画。

<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

我怎样才能做到这一点?

4

1 回答 1

4

你是正确的,你不能DataTrigger在你的Triggers收藏中使用 a 。相反,您需要使用该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>
于 2014-03-14T15:46:10.523 回答