2017-08-29 12 views

Répondre

0

Vous pouvez mettez à jour l'interface utilisateur uniquement à partir du thread d'interface utilisateur principal. Pour ce faire, vous devez utiliser la méthode Device.BeginInvokeOnMainThread pour appeler la mise à jour de l'interface utilisateur sur le thread d'interface utilisateur. Comme si:

GalaSoft.MvvmLight.Messaging.Messenger.Default.Register<status>(this, async Status=> 
     { 
      Device.BeginInvokeOnMainThread(() => 
      { 
       this.txt1.text = "Hi"; 
      }); 
     }); 

Chaque plate-forme a sa propre méthode native à invoquer sur le thread UI. En WinPhone:

GalaSoft.MvvmLight.Messaging.Messenger.Default.Register<status>(this, async Status=> 
     { 
      var coreWindow = CoreWindow.GetForCurrentThread(); 

      // Dispatcher needed to run on UI Thread 
      dispatcher = coreWindow.Dispatcher; 

      // RunAsync all of the UI info. 
      dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => 
      { 
       this.txt1.text = "Hi"; 
      }); 
     }); 
+0

Merci .. mais je suis en utilisant Xamarin natif –

+0

@ElstineP Je viens de mettre à jour mon réponse pour Xamarin.winphone –