1 Attachment(s)
WPF Combo Box doesn't rollup until the event is processed.
I have a small program which has a combobox and a text box on it.
In the combo box selection changed event, i have something like this
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
System.Threading.Thread.Sleep(10000);
textBox1.Text = "Something";
}
When ever i select something from the combox box, it waits 10sec and displays "Something" in textBox1. But the problem here is until 10sec, the combobox stay open, then displays text and then rollup. That means it is waiting until selectionchanged event to completed to rollup.
How can i make the combobox rollup(or close) ones a value is selected.
I am attaching a picture, which shows the rolldown of combobox(If what i said above is not clear)
Thank You for any help!!!!
Re: WPF Combo Box doesn't rollup until the event is processed.
What is the reason to wait for 10secs?
Re: WPF Combo Box doesn't rollup until the event is processed.
The reason to wait 10 seconds is to show the rolldown of the combobox. In actual i have lot of code to process inside the slectionchanged event which takes about 50seconds. To mimic that behaviour i just had a 10sec lag in there.
Thank You! I figured out how to do it.
Create seperate thread for 10 second wait and fill TextBox after that.
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(ExecuteThread));
th.Start();
}
private void ExecuteThread()
{
System.Threading.Thread.Sleep(10000);
this.Dispatcher.Invoke(new Action(delegate()
{
textBox1.Text = "Something";
})
);
}