问题与更新我的UI [英] Issue with updating my UI

查看:130
本文介绍了问题与更新我的UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮并使用绑定到一个字符串(名称从类属性

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

我有以下的code:

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

通过绑定我只看到:名称2 之后运行

With Binding I only see: Name2 after runtime.

我要看看名1 然后在1秒钟后看到名称2

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

我如何实现这一点?
请告诉我的此方法?

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

我也想用MVVM - 图案如果这是重要的。

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

推荐答案

使用的 线程池 是这样的:

Use ThreadPool like this:

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

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

在这里 你可以找到另一篇关于线程池的更多细节。

这篇关于问题与更新我的UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆