Issue with updating my UI

自闭症网瘾萝莉.ら 提交于 2019-12-19 10:43:41

问题


I have a Button and use binding to a string (Name property from class Person)

I have the following code:

person1.name = "Name1";
Thread.Sleep(1000);
person1.name = "Name2";

With Binding I only see: Name2 after runtime.

I want to see Name1 then after 1 second see Name2!

How can I realize this? Whats the best method for this?

I also want to use the MVVM - Pattern if this is important.


回答1:


Use ThreadPool like this:

person1.name = "Name1";
ThreadPool.QueueUserWorkItem(_ =>
{
     Thread.Sleep(1000);

     Dispatcher.BeginInvoke(new Action(() =>
     {
         person1.name = "Name2";
     }));
});

Here you can find another post about ThreadPool in more details.



来源:https://stackoverflow.com/questions/33316791/issue-with-updating-my-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!