C# 从服务器下载字符串时如何显示文本块

C# 从服务器下载字符串时如何显示文本块,c#,windows-phone,C#,Windows Phone,我的Windows Phone应用程序从服务器下载了一个字符串。我正在尝试在下载执行时显示文本块。但是,我的代码不起作用。 文本块不显示。为什么?还有别的办法吗 WebClient webClient1 = new WebClient(); webClient1.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback); webClient1.DownloadSt

我的Windows Phone应用程序从服务器下载了一个字符串。我正在尝试在下载执行时显示文本块。但是,我的代码不起作用。 文本块不显示。为什么?还有别的办法吗

 WebClient webClient1 = new WebClient();
 webClient1.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
 webClient1.DownloadStringCompleted += webClient_DownloadStringCompleted1;
 webClient1.DownloadStringAsync(new Uri(string.Format(url + insCodComanda.Text + "&random=" + ran.Next().ToString(), UriKind.RelativeOrAbsolute)));

 public void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
  {

     testete.Visibility = Visibility.Visible;

  }

void webClient_DownloadStringCompleted1(object sender, DownloadStringCompletedEventArgs e)
    {
      testete.Visibility = Visibility.Collapsed;
    }

如果您想像这样操作UI元素,您需要使用
Dispatcher

this.Dispatcher.BeginInvoke(new Action(() => testete.Visibility = Visibility.Visible));

谢谢你的回答!此代码启动了异常:
“System.Windows.Threading.Dispatcher”不包含“Invoke”的定义,并且找不到接受“System.Windows.Threading.Dispatcher”类型的第一个参数的扩展方法“Invoke”(是否缺少using指令或程序集引用?)
抱歉,请尝试
此.Dispatcher.BeginInvoke
。我没有要测试的Windows Phone环境,与WPFNo problem@ReneSá相比,它删除了一些方法。很高兴这有帮助