PushAsync is not globally supported on iOS, please use NavigationPage

Everything works fine when I handle the event of a tap-off of an ListViewelement, but when I use it in TabbedPageit shows an exception, please provide a solution to this problem in advance thanks.

Exception: PushAsync is not supported globally on iOS, please use 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());
    }                    
+4
source share
4 answers

This error occurs when launched only in iOS.

In the root directory of App.cs (start page), enter below

 public App()
  {
      MainPage=new NavigationPage(new LoginPage());
  }

Now we can use PushAsyn () in the global

+6
source

, , App.xaml.cs:

public App()
{
    InitializeComponent();

    var tabs = new TabbedPage();    
    tabs.Children.Add(new NavTestPage() { Title = "Tab title" });
    MainPage = tabs;
}

:

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;
}

NavigationPage, . A TabbedPage - 1 . ​​:

TabbedPage
    NavigationPage
        ContentPage
    NavigationPage
        ContentPage
    NavigationPage
        ContentPage

Update: , ContentPage TabbedPage XAML. , TabbedPage. , , TabbedPage.

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/

, , XAML :

<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>

MainPage App.xaml.cs:

public App()
{
    InitializeComponent();
    MainPage = new MyTabbedPage();
}
+1

You must put your TabbedPage child page in the NavigationPage. The following are snippets of code from the 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 the 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);
    }
}
0
source

In this error, he goes over and finds the root page, and if we use the details page of the wizard, we should set the navigation only for the page with details. So the following will be the best solution for this.

((RootPage)Application.Current.MainPage).Detail.Navigation.PushAsync(new SearchPage());
0
source

Source: https://habr.com/ru/post/1681483/


All Articles