我对listview有疑问。 VM上有命令将我带到另一个页面(导航服务基本上是NavigationPage.PushAsync)。点击“添加”按钮是没有问题的。在工具栏上,但单击上下文操作会引发异常。它只发生在Android,iOS和WP上工作正常。我使用的是Xamarin.Forms 1.5.0.6447。这是Xamarin的错误吗?有没有解决方法?
代码如下所示:
public Page1()
{
InitializeComponent();
listView.ItemsSource = new List<string>() {"Item1", "Item2", "Item2"};
}
private void MenuItem_OnClicked(object sender, EventArgs e)
{
App.Current.MainPage.Navigation.PushAsync(new Page2());
}
<ContentPage.ToolbarItems>
<ToolbarItem Text="ActionToolbar" Clicked="MenuItem_OnClicked"></ToolbarItem>
</ContentPage.ToolbarItems>
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="ActionContext" Clicked="MenuItem_OnClicked"></MenuItem>
</ViewCell.ContextActions>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding .}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
9-29 08:51:49.395 I/MonoDroid( 367): UNHANDLED EXCEPTION:
09-29 08:51:49.400 I/MonoDroid( 367): System.ArgumentException: 'jobject' must not be IntPtr.Zero.
09-29 08:51:49.400 I/MonoDroid( 367): Parameter name: jobject
09-29 08:51:49.400 I/MonoDroid( 367): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) <IL 0x0001f, 0x000c8>
09-29 08:51:49.400 I/MonoDroid( 367): at Android.Views.ActionModeInvoker.Finish () <IL 0x00038, 0x0013f>
09-29 08:51:49.400 I/MonoDroid( 367): at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClicked (Android.Views.ActionMode,Android.Views.IMenuItem) <IL 0x0001e, 0x00127>
09-29 08:51:49.400 I/MonoDroid( 367): at Android.Views.ActionMode/ICallbackInvoker.n_OnActionItemClicked_Landroid_view_ActionMode_Landroid_view_MenuItem_ (intptr,intptr,intptr,intptr) <IL 0x0001c, 0x00153>
09-29 08:51:49.400 I/MonoDroid( 367): at (wrapper dynamic-method) object.a3e64c2b-1708-4b07-8091-f8943a9b230f (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x00053>
09-29 08:51:49.410 W/art ( 367): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
答案 0 :(得分:2)
添加:
await Task.Yield();
在Navigation.PushAsync帮助之前。