1
votes

Coming from UWP's development, i wondering is it is possible to have navigation inside a Frame in Xamarin Forms. I saw on documentation Frame element have INavigation property, so i tried this code :

MyFrame.Navigation.PushAsync(new Page1());

But when i'm trying to execute this code on Android, i get the following error :

System.InvalidOperationException: 'PushAsync is not supported globally on Android, please use a NavigationPage.'

But when i do this :

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

The navigation does not work as expected because it is global and not inside the Frame. We have to have a global navigation or it is impossible to have a specific navigation ? The goal is to have a static part in the app and a part where navigation takes place.

For example, with Uno Platform we can use UWP Frame and perform navigation inside it, so i wondering why it is not possible in Xamarin Forms.

1

1 Answers

1
votes

We could define a property with type of INavigation in a custom Frame

public class MyFrame:Frame
{
    public INavigation CurrentNavigation { get; private set; }

    public MyFrame (INavigation navigation)
    {
        CurrentNavigation = navigation;
    }

}

in MainPage

public MainPage()
    {
        InitializeComponent();
        MyFrame myFrame = new MyFrame(this.Navigation);
        myFrame.CurrentNavigation.PushAsync(new Page1());

    }