2
<DockPanel Name="MyPanel" IsVisibleChanged="MyPanel_IsVisibleChanged">
            <DockPanel.Triggers>
                <EventTrigger RoutedEvent="IsVisibleChanged"> // error here

                </EventTrigger>
            </DockPanel.Triggers>
 </DockPanel>

以上是我的停靠面板 xmal 代码。因为 IsVisibleChanged 不是 RoutedEvent 我无法在 EventTrigger 中添加此代码:

<Storyboard x:Key="hideMe">
        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2" To="0.0"/>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{x:Static Visibility.Hidden}"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="showMe">
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:5" To="0.75"/>
    </Storyboard>

我尝试为我的停靠面板提供淡出动画。

4

1 回答 1

3

我不会使用事件触发器,而是使用普通触发器来检查Visibility.DockPanel

您可以在 DockPanel 上创建一个样式来执行此操作,如下所示:

<DockPanel Name="MyPanel">
    <DockPanel.Style>
        <Style TargetType="DockPanel">
            <Style.Triggers>
                <Trigger Property="Visibility" Value="Visible">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <!-- Set storyboard to run when DockPanel is set visible here: -->

                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard>
                            <!-- Set storyboard to run when DockPanel is no longer set visible here: -->

                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DockPanel.Style>
</DockPanel>
于 2012-11-25T21:50:10.070 回答