WPF DataTrigger和EventTrigger的组合不起作用

时间:2012-07-11 13:54:04

标签: c# wpf xaml datatrigger eventtrigger

我对我的代码有一点疑问:

<Style TargetType="{x:Type Grid}">
    <Setter Property="Visibility" Value="Collapsed"/>
    <Style.Triggers>
        <DataTrigger Binding="{Binding Status.IsObjectSaving}" Value="True">
            <Setter Property="Visibility" Value="Visible"/>
        </DataTrigger>
        <Trigger Property="Visibility" Value="Visible">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetProperty   = "Opacity"
                            From                        ="1"
                            To                          = "0"
                            BeginTime                   = "0:0:0"
                            Duration                    = "0:0:2" />
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetProperty   = "Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0:0:2"
                            Value="{x:Static Visibility.Collapsed}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
        </Trigger>
    </Style.Triggers>
</Style>

当我的对象被保存以便网格应该打开时显示一些信息。当我第一次启动程序时,它可以工作,但第二次它不起作用。所以我希望你能帮助我。

谢谢Daniel

P.S。对不起我可怕的英语!


感谢您的回答!我尝试使用以下代码设置值:

<DataTrigger Binding="{Binding Status.IsObjectSaving}" Value="True">
    <DataTrigger.EnterActions>
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation
                    Storyboard.TargetProperty   = "Opacity"
                    From                        = "0"
                    To                          = "1"
                    BeginTime                   = "0:0:0"
                    Duration                    = "0:0:2" />
                <ObjectAnimationUsingKeyFrames
                    Storyboard.TargetProperty   = "Visibility">
                    <DiscreteObjectKeyFrame KeyTime="0:0:2"
                        Value="{x:Static Visibility.Visible}" />
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation
                    Storyboard.TargetProperty   = "Opacity"
                    From                        = "1"
                    To                          = "0"
                    BeginTime                   = "0:0:2"
                    Duration                    = "0:0:2" />
                <ObjectAnimationUsingKeyFrames
                    Storyboard.TargetProperty   = "Visibility">
                    <DiscreteObjectKeyFrame KeyTime="0:0:2"
                        Value="{x:Static Visibility.Collapsed}" />
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.ExitActions>
</DataTrigger>

但它不起作用。那么你能帮我修改一下正确的代码吗?

感谢

丹尼尔

1 个答案:

答案 0 :(得分:0)

动画更改precedence更高的值,一旦可见性发生变化,触发器将无法对其进行修改。您可以使用动画替换setter(进入和退出操作),这样它们具有相同的优先级。