简体   繁体   English

Xamarin表单-WCF完成的事件未更改组件

[英]Xamarin Forms - WCF completed event not changing components

Currently i'm working on a Xamarin.Forms application with WCF. 目前,我正在使用WCF开发Xamarin.Forms应用程序。 The app makes a connection to the WCF host and I get a response back, only I can't do anything with the results of the response. 该应用程序建立了与WCF主机的连接,并且我得到了响应,但是响应结果却是我无能为力。

My code of the method that's supposed to take care of the response is: 我应该处理响应的方法的代码是:

private static void ClientOnGetHelloDataCompleted(object sender, GetHelloDataCompletedEventsArgs getHelloDataCompletedEventArgs)
{
string msg = null;

if(getHelloDataCompletedEventArgs.Error != null)
   {
      msg = getHelloDataCompletedEventArgs.Error.Message;
   }
   else if(getHelloDataCompletedEventArgs.Cancelled != null)
   {
      msg = "Request was cancelled";
   }
   else
   {
      lblText.Text = getHelloDataCompletedEventArgs.Results.Name;
   }
}

When I debug I can see Results.Name is filled, but for some reason it doesn't update the label named lblText. 当我调试时,我可以看到Results.Name已填充,但是由于某种原因,它不会更新名为lblText的标签。

This method is placed in de App.cs (Xamarin Forms portable project). 该方法位于de App.cs(Xamarin Forms可移植项目)中。

Anyone here that can help me with this problem? 这里有人可以帮助我解决这个问题吗?

you should refresh the UI in the main thread, here is the fix 您应该在主线程中刷新UI,这是解决方法

  else
  {  
         InvokeOnMainThread(() =>   lblText.Text =   getHelloDataCompletedEventArgs.Results.Name);

   }

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

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