简体   繁体   English

烤面包机弹出仅显示一次

[英]Toaster Popup only showing once

I have the following XAML for a "toaster" popup: 对于“烤面包机”弹出窗口,我具有以下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>

The problem with this Popup is that it only seems to work once. 此弹出窗口的问题在于它似乎只能工作一次。 I set popupMessage.IsOpen = true and this shows the popup one time. 我设置popupMessage.IsOpen = true ,这一次显示了弹出窗口。 All subsequent calls don't let the popup appear. 随后的所有呼叫均不让弹出窗口出现。 I checked and the IsOpen property is indeed set to false at the end of the animation. 我检查了IsOpen ,动画结束时IsOpen属性确实设置为false。

Clearly I'm missing something here, but what? 显然我在这里缺少什么,但是呢?

You need to stop your storyboard in the ExitActions of your Trigger. 您需要在触发器的ExitActions中停止情节提要。

Try this: 尝试这个:

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

I had a similar issue when changing the background colour of a control using an animation and it would also only work once. 使用动画更改控件的背景色时,我遇到了类似的问题,并且它也只能工作一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM