Muhammad Danish
Muhammad Danish

Reputation: 109

using delay in tab control before the data is insert into textbox in wpf

I am new in wpf. I am using the tabcontrol. and there are two tabs. I want that on change the tab all the contents of tab load. and then I am inserting some text in a text box. I want delay of 5 sec before text is insert in textbox. I illustrate this with images. below is the open tabcontrol.

enter image description here

When I click on connect its display the following.

enter image description here

on right side there is a textbox with text "vokkey, Dave". I want that after the tab load it's wait for 5 second and then the text "vokkey,dave" appear in textbox. on which event should i work.? and for delay what should i do?

Upvotes: 0

Views: 191

Answers (1)

Sheridan
Sheridan

Reputation: 69985

It is customary to use a DispatcherTimer for these situations... put this into your UserControl:

In the constructor:

Loaded += YourControl_Loaded;

Then in the code behind of the UserControl:

private void YourControl_Loaded(object sender, RoutedEventArgs e)
{
    DispatcherTimer timer = new DispatcherTimer();
    timer.Interval = new TimeSpan(0, 0, 5);
    timer.Tick += Timer_Tick;
    timer.Start();
}

...

private void Timer_Tick(object sender, EventArgs e)
{
    TextBox.Text = "vokkey, Dave";
    timer.Stop();
}

You can find out more about the DispatcherTimer from the DispatcherTimer Class page at MSDN.

Upvotes: 1

Related Questions