Timer in WPF


  1. private void Window_Loaded(object sender, RoutedEventArgs e)   
  2.    
  3. {   
  4.    
  5.     DispatcherTimer dispatcherTimer = new DispatcherTimer();   
  6.    
  7.     dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);   
  8.    
  9.     dispatcherTimer.Interval = new TimeSpan(0, 0, 1);   
  10.    
  11.     dispatcherTimer.Start();   
  12.    
  13. }   
  14.    
  15.     
  16.    
  17. private void dispatcherTimer_Tick(object sender, EventArgs e)   
  18.    
  19. {   
  20.    
  21.     listBox1.Items.Add(DateTime.Now.Hour.ToString() + ":" +   
  22.    
  23.         DateTime.Now.Second.ToString());   
  24.    
  25.        
  26.    
  27.     CommandManager.InvalidateRequerySuggested();   
  28.    
  29.     listBox1.Items.MoveCurrentToLast();   
  30.    
  31.     listBox1.SelectedItem = listBox1.Items.CurrentItem;   
  32.    
  33.     listBox1.ScrollIntoView(listBox1.Items.CurrentItem);   
  34.    
  35. }  



Multi-coloured code for a blog http://aivolkov.ru/online-syntax-highlighter/

No comments:

Post a Comment

Note: only a member of this blog may post a comment.