當我單擊與 Web 服務對話的按鈕然后單擊另一個按鈕時,我遇到了 Android 應用程式問題,我得到了這個例外。
無法從本機句柄 0x7fcb566738 (key_handle 0x3ed634c) 激活 Xamarin.Forms.Platform.Android.FastRenderers.FrameRenderer 型別的實體。
例外似乎來自以下 xaml
<Frame x:Name="TileFrame" Margin="5" Grid.Column="0" Grid.Row="0"
BindingContext="{x:Reference this}"
effects:TouchEffect.Command="{Binding TapTile}"
effects:TouchEffect.CommandParameter="{Binding}">
<StackLayout VerticalOptions="Center">
<Label
BindingContext="{x:Reference this}"
Text="{Binding Title}"
FontSize="20"
LineHeight="1"
FontAttributes="Bold"
TextTransform="Uppercase"
HorizontalTextAlignment="Center"
Opacity="1"
Margin="5, 0" />
</StackLayout>
</Frame>
如果我將框架更改為按鈕,則會出現以下例外
<Button x:Name="TileFrame" Margin="5" Grid.Column="0" Grid.Row="0"
BindingContext="{x:Reference this}"
effects:TouchEffect.Command="{Binding TapTile}"
effects:TouchEffect.CommandParameter="{Binding}">
</Button>
無法從本機句柄 0x7fcb55a1d8 (key_handle 0x46ac678) 激活 Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer 型別的實體。
我在 git hub 上找到了這個,但它是從 2020 年開始的,我看到有同樣的問題,到目前為止,解決方法并沒有解決我的問題
https://github.com/xamarin/Xamarin.Forms/issues/9136
uj5u.com熱心網友回復:
所以經過大量的挖掘。該應用程式在 UI 上做事,并不總是在 UI 執行緒上。因此,將代碼包裝在以下代碼中,可為應用程式提供更高的穩定性。
MainThread.BeginInvokeOnMainThread(() =>
{
// Code to run on the main thread
});
https://docs.microsoft.com/en-us/xamarin/essentials/main-thread
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/425096.html
