Everything is working fine when I am handling the Tap event of a ListView
item, but when I use this in a TabbedPage
it shows the exception please provide a solution to this problem thanks in advance.
Exception: PushAsync is not supported globally on iOS, please use a NavigationPage.
Here is the Xaml Code:
<?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>
Here's the OnClick Handler:
async void Handle_Clicked(object sender, System.EventArgs e)
{
await Navigation.PushAsync(new Page1());
}
This error will come while running in iOS only.
In App.cs Rootpage(Start page) give like below
public App()
{
MainPage=new NavigationPage(new LoginPage());
}
Now, We can use PushAsyn() in Globally
You probably have some code somewhere similar to this in your App.xaml.cs
:
public App()
{
InitializeComponent();
var tabs = new TabbedPage();
tabs.Children.Add(new NavTestPage() { Title = "Tab title" });
MainPage = tabs;
}
Which you should change to:
public App()
{
InitializeComponent();
var tabs = new TabbedPage();
var page = new NavTestPage() { Title = "Page title" };
tabs.Children.Add(new NavigationPage(page) { Title = "Tab title" });
MainPage = tabs;
}
By wrapping in a NavigationPage
you get the option to push pages onto the navigation stack. A TabbedPage
on itself is just tabs with only 1 page per tab. This should give you a structure like this:
TabbedPage
NavigationPage
ContentPage
NavigationPage
ContentPage
NavigationPage
ContentPage
Update:
I guess what you're doing is simply changing ContentPage
to TabbedPage
in your XAML. That's not how TabbedPage
works. You should probably read up on how TabbedPage
actually works in the first place.
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/
In your case you should probably create a new page which has XAML like this:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:NavTest"
x:Class="NavTest.MyTabbedPage">
<NavigationPage Title="NavTest">
<x:Arguments>
<local:NavTestPage />
</x:Arguments>
</NavigationPage>
</TabbedPage>
Set this as the MainPage
in App.xaml.cs
:
public App()
{
InitializeComponent();
MainPage = new MyTabbedPage();
}
You should put your TabbedPage child page into NavigationPage. The following is code snippets from Xamarin documentation.
In Xaml:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
x:Class="TabbedPageWithNavigationPage.MainPage">
<local:TodayPage />
<NavigationPage Title="Schedule" Icon="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>
</TabbedPage>
Or In Code:
public class MainPageCS : TabbedPage
{
public MainPageCS ()
{
var navigationPage = new NavigationPage (new SchedulePageCS ());
navigationPage.Icon = "schedule.png";
navigationPage.Title = "Schedule";
Children.Add (new TodayPageCS ());
Children.Add (navigationPage);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With