按下键时如何终止循环执行?

时间:2018-06-26 08:26:53

标签: visual-studio-lightswitch

我有一个场景,我要逐个显示集合的内容,直到按下某个键。问题是我无法获得正确的代码来确定何时按下某个键。我正在使用VB.net语言在Visual Studio Lightswitch中进行设计。下面的链接显示了我程序的输出。 Sample output of the program。显示器不断循环播放,直到用户按下一个键。下面也是我正在使用的示例代码。

    Private Sub Compliances_Activated()
        ' Write your code here.
       Do until "***the problem is here, I suppose to handle keyevents here but with no luck."***
            For Each I In Me.PendingCompliance
                If I.Incharge = "S1" Then
                    Me.Partic = I.Particulars
                    Me.ActionToUndertake = I.ActionToUndertake
                    Me.StatusOfCompliance = I.StatusOfCompliance
                    Dim controlcurr1 = Me.FindControl("Partic1")
                    AddHandler controlcurr1.ControlAvailable, _
                        Sub(sender As Object, e As ControlAvailableEventArgs)
                            Dim textbox = CType(e.Control, System.Windows.Controls.TextBlock)
                            textbox.Foreground = New SolidColorBrush(Color.FromArgb(200, 0, 126, 230))
                            textbox.Height = (400.0)
                            textbox.FontSize = Convert.ToDouble(72.0)
                            textbox.FontFamily = New FontFamily("arial")
                            textbox.TextTrimming = TextTrimming.None

                        End Sub

                    Dim newsText1 = Me.FindControl("Partic1")
                    AddHandler newsText1.ControlAvailable, Sub(sender, e)

                                                               'Get the istance
                                                               Dim block = CType(e.Control, TextBlock)

                                                               'Set a different color, if you like
                                                               block.Foreground = New SolidColorBrush(Colors.Black)

                                                               'Create an animation
                                                               Dim sb As New Storyboard
                                                               Dim colorAnim As New ColorAnimation
                                                               colorAnim.AutoReverse = True
                                                               colorAnim.RepeatBehavior = RepeatBehavior.Forever
                                                               colorAnim.From = Colors.Blue
                                                               colorAnim.To = Colors.White
                                                               colorAnim.Duration = TimeSpan.FromSeconds(8)

                                                               'Apply the animation
                                                               Storyboard.SetTarget(colorAnim, block.Foreground)
                                                               Storyboard.SetTargetProperty(colorAnim, New PropertyPath("Color"))
                                                               sb.Children.Add(colorAnim)
                                                               sb.Begin()

                                                           End Sub

如果结束                          下一个 请帮助

1 个答案:

答案 0 :(得分:0)

您正在使用什么?

可能会是这样

String answer;
If(answer!=" ")

break;