简体   繁体   中英

Xamarin Forms - WCF completed event not changing components

Currently i'm working on a Xamarin.Forms application with WCF. 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.

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.

This method is placed in de App.cs (Xamarin Forms portable project).

Anyone here that can help me with this problem?

you should refresh the UI in the main thread, here is the fix

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

   }

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