2017-08-29 136 views

回答

0

你可真糊涂变量的值只从主UI线程更新UI。为此,您需要使用Device.BeginInvokeOnMainThread方法在UI线程上调用UI的更新。像这样:

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

每个平台都有它自己的本地方法来调用UI线程。在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

谢谢..但我使用xamarin原生 –

+0

@ElstineP我刚刚更新了我的答案Xamarin.winphone –