0

我有以下 XAML 用于“烤面包机”弹出窗口:

<Popup x:Name="popupMessage"
           Width="500"
           Height="100"
           IsOpen="False"
           Placement="Top"
           PlacementTarget="{Binding ElementName=statusBarMain}"
           StaysOpen="True">

        <Popup.Style>
            <Style>
                <Style.Triggers>
                    <Trigger Property="Popup.IsOpen" Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                                        <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                        <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                                        <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                        <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                                        <SplineDoubleKeyFrame KeyTime="0:0:2" Value="1" />
                                        <SplineDoubleKeyFrame KeyTime="0:0:4" Value="0" />
                                    </DoubleAnimationUsingKeyFrames>
                                    <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen">
                                        <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True" />
                                        <DiscreteBooleanKeyFrame KeyTime="0:0:4" Value="False" />
                                    </BooleanAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Popup.Style>
        <Popup.RenderTransform>
            <ScaleTransform ScaleY="1" />
        </Popup.RenderTransform>

        <Border Width="504"
                Height="104"
                BorderBrush="#FF0F3D5C"
                BorderThickness="2">
            <Border Width="500"
                    Height="100"
                    BorderBrush="White"
                    BorderThickness="2">
                <Border.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Offset="0" Color="#FFD3CCF5" />
                        <GradientStop Offset="1" Color="#FF0F3D5C" />
                    </LinearGradientBrush>
                </Border.Background>

                <TextBlock x:Name="textBlockMessage"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           FontSize="18"
                           Foreground="White"
                           Text="{Binding NotificationMessage}" />

            </Border>
        </Border>
    </Popup>

这个弹出窗口的问题是它似乎只工作一次。我设置popupMessage.IsOpen = true了,这显示了一次弹出窗口。所有后续调用都不会让弹出窗口出现。我检查并IsOpen在动画结束时该属性确实设置为 false。

显然我在这里遗漏了一些东西,但是什么?

4

1 回答 1

0

您需要在触发器的 ExitActions 中停止情节提要。

试试这个:

<Trigger Property="Popup.IsOpen" Value="True">
   <Trigger.EnterActions>
      <BeginStoryboard Name="OpenStoryboard">
          <Storyboard>
              <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                  <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                  <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
              </DoubleAnimationUsingKeyFrames>
              <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                  <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                  <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
                  <SplineDoubleKeyFrame KeyTime="0:0:2" Value="1" />
                  <SplineDoubleKeyFrame KeyTime="0:0:4" Value="0" />
              </DoubleAnimationUsingKeyFrames>
              <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen">
                  <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True" />
                  <DiscreteBooleanKeyFrame KeyTime="0:0:4" Value="False" />
              </BooleanAnimationUsingKeyFrames>
          </Storyboard>
      </BeginStoryboard>
   </Trigger.EnterActions>
   <Trigger.ExitActions>
      <StopStoryboard BeginStoryboardName="OpenStoryboard"/>
   </Trigger.ExitActions>
</Trigger>

在使用动画更改控件的背景颜色时,我遇到了类似的问题,它也只能工作一次。

于 2013-10-04T08:06:16.623 回答