繁体   English   中英

WP7工具包PerformanceProgresBar和UI线程(丢失点效果)

[英]WP7 Toolkit PerformanceProgresBar and UI thread (losing dots effect)

我很难管理WP Toolkit中的ProgressBar。 在我的项目中,我有一个列表框,其中填充了数据绑定项。 填充过程如下:

  1. 显示进度条(可见性更改为可见,IsIndeterminate更改为true),
  2. 提出休息请求,
  3. 得到回应
  4. 解析项目集合,
  5. 将内存中的项目绑定到列表,
  6. 隐藏进度条(可见性为折叠,IsIndeterminate为false)。

我现在的问题是:Indeterminate标志似乎改变得太快(我认为不同的线程?)。 这导致进度条有时只显示一个矩形。 如何确保仅在数据绑定和列表框刷新完成后进度条才会消失?

这是我的响应回调:

private void DataLoaded(object o, RestResponseEventArgs e)
{   
  int i = 0;
  List<Entry> entries = new List<Entry>();
  foreach (JObject current in e.JsonObject["entries"].Children())
  {
     Entry e = Entry.Parse(current);
     entries.Add(e);
  }
  this.MyListBox.ItemsSource = entries;
  this.ProgressBar.Visibility = Visibility.Collapsed;
  this.ProgressBar.IsIndeterminate = false;
}

使用Dispatcher.BeginInvoke()方法:

    private void DataLoaded(object o, RestResponseEventArgs e)
    { 
      Dispatcher.BeginInvoke(() =>
      {
       int i = 0;
       List<Entry> entries = new List<Entry>();
       foreach (JObject current in e.JsonObject["entries"].Children())
       {
         Entry e = Entry.Parse(current);
         entries.Add(e);
       }
       this.MyListBox.ItemsSource = entries;
       this.ProgressBar.Visibility = Visibility.Collapsed;

   this.ProgressBar.IsIndeterminate = false;
  });    
}

暂无
暂无

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

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