2017-08-29 138 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 –