我有一个计时器。在我的表单中仍然可以打开子窗口。当我打开并关闭此窗口时,计时器再次启动。当我打开和关闭子窗口时,如何继续计时器操作?我非常希望得到你的帮助! 这是我的计时器:
Private timer As DispatcherTimer
Private CountUp As Integer
Public Sub DispatcherTimerSetup()
timer = New DispatcherTimer()
timer.Interval = New TimeSpan(0, 0, 1)
AddHandler timer.Tick, AddressOf timer_Tick
timer.Start()
End Sub
Private Sub timer_Tick(sender As Object, e As Object)
CountUp += 1
Dim counter As TimeSpan
counter = TimeSpan.FromSeconds(CountUp)
txblCountdown.Text = counter.ToString("mm\:ss")
End Sub
子窗口:
Private Sub btnMapPoint_Click(sender As Object, e As RoutedEventArgs)
SaveControlValuesInObject()
Dim intIndex As Integer = CInt(sender.Name.Replace("btnMapPoint_", ""))
Frame.Navigate(GetType(Location))
TryCast(Frame.Content, Location).InitForm_Observation(_myEventErist, intIndex, GetType(Event9900000))
TryCast(Frame.Content, Location).IsChangeMapEnabled = False
TryCast(Frame.Content, Location).SetSelectedMap(DirectCast(cboMesspunkt.SelectedItem, SMS_KARTE))
End Sub
最好的问候,Polina
答案 0 :(得分:0)
Frame.Navigate(GetType(Location))
会初始化Location
页面的新实例,因此CountUp
值将会丢失。
您可以将CountUp
字段设为公开,并在父对象中添加其他字段,例如SavedCountUpValue
。然后使用Location.Unloaded
事件将CountUp
值保存到SavedCountUpValue
字段。
在父对象中,在Location_Unloaded
处理程序中:
SavedCountUpValue = TryCast(Frame.Content, Location).CountUp
然后,在初始化新的Location
对象时,请恢复CountUp
值。
在父对象中,在btnMapPoint_Click
处理程序中:
Frame.Navigate(GetType(Location))
...
TryCast(Frame.Content, Location).CountUp = SavedCountUpValue