0
當我試圖改變如何解決線程問題在塊
GalaSoft.MvvmLight.Messaging.Messenger.Default.Register<status>(this, async Status=>
{
this.txt1.text = "Hi"
});
我對如何處理這個錯誤
當我試圖改變如何解決線程問題在塊
GalaSoft.MvvmLight.Messaging.Messenger.Default.Register<status>(this, async Status=>
{
this.txt1.text = "Hi"
});
我對如何處理這個錯誤
你可真糊塗變量的值只從主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";
});
});
謝謝..但我使用xamarin原生 –
@ElstineP我剛剛更新了我的答案Xamarin.winphone –