当我处理 ListView
项目的Tap事件时,一切正常,但是当我在 TabbedPage
中使用它时,它会显示异常请提前解决此问题 .
例外:iOS上不支持全局支持PushAsync,请使用NavigationPage .
这是Xaml代码:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:NavTest" x:Class="NavTest.NavTestPage" Title="Home">
<ContentPage.Content>
<StackLayout Orientation="Vertical" VerticalOptions="Center">
<Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
<!--<Button Text="Go to " BackgroundColor="Lime" VerticalOptions="Center" Clicked="Handle_Clicked" >
</Button>-->
<ListView x:Name="myListView" ItemSelected="Handle_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding}" VerticalOptions="Center" HorizontalOptions="Center" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
这是OnClick处理程序:
async void Handle_Clicked(object sender, System.EventArgs e)
{
await Navigation.PushAsync(new Page1());
}
4 回答
仅在iOS中运行时会出现此错误 .
In App.cs Rootpage(Start page) give like below
现在,我们可以在全球范围内使用PushAsyn()
你可能在_1295859中有一些与此类似的代码:
你应该改为:
通过包装
NavigationPage
,您可以选择将页面推送到导航堆栈 .TabbedPage
本身就是每个标签只有1页的标签 . 这应该给你一个这样的结构:Update: 我猜你正在做的只是在你的XAML中将
ContentPage
改为TabbedPage
. 这不是TabbedPage
的工作方式 . 您应该首先阅读TabbedPage
实际上是如何工作的 .https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/
在您的情况下,您应该创建一个新页面,其中包含XAML,如下所示:
在
App.xaml.cs
中将其设置为MainPage
:您应该将TabbedPage子页面放入NavigationPage . 以下是Xamarin文档中的代码片段 .
In Xaml:
Or In Code:
在这个错误中,它会找到根页面,如果我们使用主详细信息页面,那么我们只需要为详细信息页面设置导航 . 因此,以下将是最佳解决方案 .