简体   繁体   English

更新我的UI的问题

[英]Issue with updating my UI

I have a Button and use binding to a string ( Name property from class Person ) 我有一个Button并使用绑定到字符串(类Person Name属性)

I have the following code: 我有以下代码:

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

With Binding I only see: Name2 after runtime. 使用绑定,我只能看到:运行时后的Name2

I want to see Name1 then after 1 second see Name2 ! 我想看到Name1然后在1秒钟后看到Name2

How can I realize this? 我怎么能意识到这一点? Whats the best method for this? 最好的方法是什么?

I also want to use the MVVM - Pattern if this is important. 如果这很重要,我也想使用MVVM-模式。

Use ThreadPool like this: 像这样使用ThreadPool

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. Here您可以找到更多关于ThreadPool的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM