How to stop the timer running in one viewmodel in another viewmodel?
Main viewmodel
class MainWindow { public void SetTimer(object sender, RoutedEventArgs e) { System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); timer.Tick += new EventHandler(timerTick); timer.Interval = new TimeSpan(0, 0, 5); timer.Start(); } private void timerTick(object sender, EventArgs e) { Application.Current.Windows[0].Close(); } }
Child viewmodel
class ChildWindow{ public void DoSomething(){ // что-то происходит // тут должен выключаться таймер } }
In general, the idea is that I turn on the timer in one window and when I click a button, a new window opens in which the timer opened in the first window should turn off
ViewModel
instance of theDispatcherTimer
class from the mainViewModel
. Just at the moment of creation and initialization of the childViewModel
. Give some code so that you can give a more specific answer. There are ways to link modelsViewModel
stackoverflow.com/a/5732844/5275890 - Denis Bubnov