简体   繁体   English

如何刷新Metro Style应用的用户界面?

[英]How to refresh the UI of a Metro Style app?

I am trying to refresh/update the UI of a Metro Style app to reflect changes. 我正在尝试刷新/更新Metro Style应用的用户界面以反映更改。
To redraw the Controls in Windows Forms, you can simply use: 要重画Windows窗体中的控件,您可以简单地使用:

this.Refresh();    

How can I achieve a similar result in Metro Style apps? 如何在Metro Style应用中获得相似的结果?

Consider this simple example in C#: 考虑一下C#中的这个简单示例:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    btnStatus.Content = "Test started";
    Task.Delay(3000); // Wait 3 seconds
    btnStatus.Content = "Test Ended"
} 

What I need to do is: show the 'start' message, wait a few seconds and then show the 'end' message. 我需要做的是:显示“开始”消息,等待几秒钟,然后显示“结束”消息。 However, when this runs, btnStatus immediately shows 'TestEnded' - as if the first 2 statements didn't execute. 但是,当它运行时,btnStatus立即显示“ TestEnded”-好像前两个语句没有执行。

How can I fix this? 我怎样才能解决这个问题?

I have looked at: How to refresh the UI in a metro app? 我看过: 如何在Metro应用程序中刷新UI? but it didn't help. 但这没有帮助。

The code you wrote is incorrect. 您编写的代码不正确。 Task.Delay() runs async, so your code naturally continues on. Task.Delay()异步运行,因此您的代码自然会继续进行。

This will work correctly... 这将正常工作...

private async void Button_Click(object sender, RoutedEventArgs e)
{
    btnStatus.Content = "Test started";
    await Task.Delay(3000); // Wait 3 seconds
    btnStatus.Content = "Test Ended"
} 

Note the addition of the await key world 注意等待密钥世界的添加

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

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