2016-09-05 9 views
0

私はタイマーを持っています。私のフォームではまだ子ウィンドウを開くことができます。このウィンドウを開いて閉じると、タイマーが再び開始します。子ウィンドウを開いたり閉じたりするときに、タイマーの操作を続行するにはどうすればいいですか?私はあなたの助けを非常に願っています! が、これは私のタイマーです:子ウィンドウを開いたり閉じたりするときにタイマーの時間を続けるには

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 

敬具、ポリーナ

+0

あなたは子ウィンドウを開いているコードを示してもらえますか?あなたがそれを開くたびに子ウィンドウが再初期化されたと仮定します。 –

+0

はい、子ウィンドウを追加しました –

答えて

0

Frame.Navigate(GetType(Location))Locationページの新しいインスタンスを初期化しますので、​​値が失われます。

​​フィールドをpublicにして、親オブジェクトに別のフィールドを追加することができます(例:SavedCountUpValue)。次にLocation.Unloadedイベントを使用して​​値をSavedCountUpValueフィールドに保存します。 Location_Unloadedハンドラ内の親オブジェクトで

、新しい Locationオブジェクトを初期化するとき

SavedCountUpValue = TryCast(Frame.Content, Location).CountUp 

その後、​​値を復元します。親オブジェクトで

は、btnMapPoint_Clickハンドラで:

Frame.Navigate(GetType(Location)) 
... 
TryCast(Frame.Content, Location).CountUp = SavedCountUpValue 
関連する問題