c# - WPF TabControl tab changes not refreshed -


I have WPF TabControl with two TabItems . I am trying to change the event and execute some other code by clicking the selected tab on the code behind the code on the button . In this example:

  Private Wide Buttonic (Object Sender, Routing Avent, ARGS E) {ConvertDataTab Control. Select Index = 1; System.Threading.Thread.Sleep (2000); ...}   

I hope to refresh the UI and go from tab 0 to tab 1 and then only The sleep method must be executed, but UI is only refreshing after finishing the Button_Click execution. I tried to call InvalidVisual , but it does not work.

What is Sleep

The code runs on the UI thread by default, so the thread can not be executed on the UI thread (such as layout) until the thread is executed.

There are several ways to issue control of the UI thread before the code is over, but I think the code can be used to run from the use of a task It's simple to do on a different thread.

For example,

  Tasks. Factor Start New (() => {Thread.Sleep (2000); // Other code here}};   

It should be noted that UI objects can only be modified on the UI thread, so if your "other code here" updates a UI object, then you might execute it Would like to use code on the UI thread, such as:

  Dispatcher.BijinWolk ((=) = & gt; {/ code to update III});    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -