Search code examples
c#wpfdispatchertimer

how to show label for couple of seconds in wpf?


I want to show a label for 3 seconds only and then disappear it. I am working on a WPF application.

public DispatcherTimer timer = new DispatcherTimer(); 
timer.Tick += new EventHandler(timer_Tick);

I started timer from the function

timer.Start(); 
    
private void timer_Tick(object sender, EventArgs e)
{
      /*
      if timer equals 3 seconds then 
      timer.stop();
      lblToast.Visibility = Visibility.Hidden;
      else
      lblToast.Visibility = Visibility.Visible;
      */
}

Is this the right way or is there any other easy way ?


Solution

  • Set your Interval to 3000 and then just hide the label in the Tick event.