public DispatcherTimer timer = new DispatcherTimer(); public MainWindow() { InitializeComponent(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += timer_Tick; timer.Start(); } void timer_Tick(object sender, EventArgs e) { lblTime.Content = DateTime.Now.ToLongTimeString(); } private void Button_Click(object sender, RoutedEventArgs e) { Window1 obj = new Window1(); obj.ShowDialog(); }
public Window1() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { MainWindow obj = new MainWindow(); obj = Application.Current.Windows.OfType<MainWindow>().SingleOrDefault(x => x.IsActive); obj.timer.Stop(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)