0

我对我的代码有一个小问题:

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

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

谢谢丹尼尔

ps 对不起我糟糕的英语!


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

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

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

谢谢

丹尼尔

4

1 回答 1

0

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

于 2012-07-11T13:58:28.527 回答