简体   繁体   中英

Refresh in silverlight seems textbox

Windows Phone似乎有命令txtBox.Text.Refesh()吗?

Before I give my reply... As HighCore suggested in the comment - you are probably doing it wrong - you should probably change how you work to fit more with the framework. That said..

You can do this in many ways, but here are two fairly trivial ones.

  1. Option 1: the fancy way.

Download and install the async CTP. This will allow you to use async/await semantics.

Do something like this:

async void Button_Click()
{
for (int i = 0; i < 100; i++)
{
textbox.Text = i.ToString();
await Task.Delay(1000);
}
}
  1. Option 2: Good'ol way.

If you don't want to install the async CTP, refactor your code in the following manner:

void Button_Click()
{
  int i = 0;
  var t = new DispatcherTimer();
  t.Interval = TimeSpan.FromSeconds(1);
  t.Tick += (s, e) => { textbox.Text = i.ToString; i++; if (i == 20) t.Stop(); };
  t.Start();
}

Note that when this code is running, your app remains responsive which means that people may activate code you don't want them to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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