【问题标题】:Disable Storyboard or Animation in WPF在 WPF 中禁用情节提要或动画
【发布时间】:2015-03-10 19:15:21
【问题描述】:

我创建了一个带有动画和一些消息的简单通知窗口。但是,我可以在例如禁用动画或情节提要吗? MouseEnter 事件,如 Facebook 通知。逐渐降低不透明度,当我在窗口上拖动鼠标时,将不透明度设置为 100%。怎么做? 这是一个xaml代码:

 WindowStyle="None" AllowsTransparency="True" Background="Transparent" >
<Grid x:Name="gridData" RenderTransformOrigin="0,1" MouseRightButtonDown="Window_MouseRightButtonDown" MouseEnter="Grid_MouseEnter">
    <Border BorderThickness="1" Background="SkyBlue" BorderBrush="Black" CornerRadius="10">
        <StackPanel Margin="20">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="32"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="40"/>
                </Grid.ColumnDefinitions>
                <TextBlock x:Name="txtTitle" Grid.Row="0" Grid.Column="0" Text="" FontWeight="Bold" VerticalAlignment="Center"/>
                <Image x:Name="image" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Visibility="Collapsed"/>
                <TextBlock x:Name="txtMessage" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="" TextWrapping="Wrap"/>
            </Grid>
        </StackPanel>
    </Border>

    <Grid.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded" >
            <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:2" Value="1"/>
                        <SplineDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>

    <Grid.RenderTransform>
        <ScaleTransform ScaleY="1" />
    </Grid.RenderTransform>

</Grid>

【问题讨论】:

    标签: c# wpf animation storyboard


    【解决方案1】:

    给你的BeginStoryboard添加一个名字:

    <BeginStoryboard Name="ScaleAndFadeOut">
    

    然后为不同的事件添加另一个事件触发器,并使用StopStoryboard 元素:

    <Grid.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            ...
        </EventTrigger>
    
        <EventTrigger RoutedEvent="FrameworkElement.MouseMove">
            <StopStoryboard BeginStoryboardName="ScaleAndFadeOut" />
        </EventTrigger>
    </Grid.Triggers>
    

    MSDN:"How to: Use Event Triggers to Control a Storyboard After It Starts"

    【讨论】:

      猜你喜欢
      • 2015-02-14
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2020-08-06
      • 2011-01-16
      • 2017-12-17
      相关资源
      最近更新 更多