现在我正在使用它,如果您有更好的方法,请告诉我。
在 xaml 中,我创建了 3 个没有触发器的故事板。
<Window.Resources>
<Storyboard x:Key="WrongBarcode">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="txtbScan">
<DiscreteStringKeyFrame KeyTime="0:0:0" Value="Wrong Barcode"/>
<DiscreteStringKeyFrame KeyTime="0:0:4" Value="Scan your barcode"/>
</StringAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="Win">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="txtbScan">
<DiscreteStringKeyFrame KeyTime="0:0:0" Value="Hurray You Won"/>
<DiscreteStringKeyFrame KeyTime="0:0:25" Value="Scan your barcode"/>
</StringAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="Unqulified">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="txtbScan">
<DiscreteStringKeyFrame KeyTime="0:0:0" Value="Please Qualify your card at the Cashier."/>
<DiscreteStringKeyFrame KeyTime="0:0:4" Value="Scan your barcode"/>
</StringAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
然后在后面的代码中
Private Sub Window_KeyDown(sender As Object, e As KeyEventArgs)
Static curBarcode As String
If e.Key = 6 Then 'Found that it hits key6 at the end of each barcode read
Select Case ValidateCard(curBarcode)
Case 0
Dim Unqulified As Storyboard = DirectCast(FindResource("Unqulified"), Storyboard)
Unqulified.Begin(Me)
Case 1
Dim win As Storyboard = DirectCast(FindResource("Win"), Storyboard)
win.Begin(Me)
Case Else
Dim WrongBarcode As Storyboard = DirectCast(FindResource("WrongBarcode"), Storyboard)
WrongBarcode.Begin(Me)
End Select
'txtbScan.Text = "Scan your gift card."
curBarcode = ""
Else
curBarcode = curBarcode & Mid(e.Key.ToString(), 2, 1)
'
End If
End Sub
我仍然需要更改获奖文本,它有很多变化。我正在考虑添加一个更大的文本块,甚至可能是一个图像,并在代码和动画可见性中设置值。
请让我知道你的想法。
谢谢