0
votes

I am trying to open (using any method) the TabbedPage from ContentPage.

My main App code:

public class App : Application
{
    public App ()
    {
        MainPage = new ConnectPage ();
    }
}

My ConnectPage uses XAML, code:

.cs file:

public partial class ConnectPage : ContentPage
    {
        public ConnectPage ()
        {
            InitializeComponent ();
        }

        void connectDevice(object sender, EventArgs args){
            connect_btn.Text = "Connecting...";
            connect_btn.IsEnabled = false;
            var mainapp_page = new MainApp ();
            Navigation.PushAsync (mainapp_page);
        }
    }

XAML file:

<Button x:Name="connect_btn" Text="Connect Now" Clicked="connectDevice"></Button>

Above method throws error:

PushAsync is not supported globally on iOS, please use a NavigationPage

My MainApp.cs (which contain tabs):

public class MainApp : ContentPage
{
    public MainApp ()
    {
        var tabs = new TabbedPage ();
        tabs.Children.Add (new Tab1Page{Title="Tab1" });
        tabs.Children.Add (new Tab2Page{Title="Tab2" });
        tabs.Children.Add (new Tab3Page{Title="Tab3" });
    }
}
1
have you tried googling that exact error message for examples on how to fix it.. since you are utilizing the PushAsync method.. one would almost automatically think that you would need to implement the await method call.. but It's a guess for me at this point..MethodMan

1 Answers

1
votes

You can either update your'r app's MainPage property and set that to the page you want to display, use stack navigation or present a page modally.

Setting a new main page will provide no way for the user to go back:

App.Current.MainPage = new SomeOtherPage ();

If you want to use stack navigation, you will have to wrap your initial page into a NavigationPage:

public partial class App : Application
{
    public App ()
    {
        InitializeComponent ();
        this.MainPage = new NavigationPage (new FirstPage ());
    }
}

Than you can use Navigation.PushAsync().

If you want to present a page modally, so it is shown on top of your current page and can be dismissed, use:

Navgiation.PushModalAsync(new Page());

However, this will still require to wrap your current page into a NavigationPage.

There are other ways too, like CarouselPage or MasterDetailPage. I recommend you look at the documentation for all of your options.