【问题标题】:WPF after animation events stop working动画事件停止工作后的 WPF
【发布时间】:2013-05-30 19:36:19
【问题描述】:

我有一个简单的窗口,用户在其中扫描条形码,然后您会根据条形码获得动画。

在第一个动画之后它停止接收 Window_KeyDown 事件。

动画是通过代码触发的,因为它需要读取条形码。

这是故事板。

    <Storyboard x:Key="Win">
        <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="txtbScan">
            <DiscreteStringKeyFrame KeyTime="0:0:05" Value="Scan your barcode"/>
        </StringAnimationUsingKeyFrames>
    </Storyboard>

我在这里调用代码。

                Dim win As Storyboard = DirectCast(FindResource("Win"), Storyboard)
                txtbScan.Text = "Hurray you won " & GetPrize(curBarcode)
                win.Begin(Me)

动画似乎在继续,无法接收下一个输入事件。

【问题讨论】:

标签: wpf vb.net animation


【解决方案1】:

是的,这是 WPF 的一个奇怪之处。在您对动画属性调用 null 动画之前,动画不会清除。试试这个:

// You have to run a 'null' animation to clear an animated property
win.BeginAnimation(TextBlock.TextProperty, null)

类似的东西。 (不确定如何正确格式化 VB)。

编辑

看看这个How to stop an animation in C# / WPF?

【讨论】:

  • 或者只是将动画的FillBehavior属性设置为Stop
猜你喜欢
  • 2012-05-23
  • 1970-01-01
  • 1970-01-01
  • 2013-03-29
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
相关资源
最近更新 更多