question

6666666 avatar image
0 Votes"
6666666 asked ColeXia-MSFT answered

How to access PushAsync in cs file not the xmal.cs?

I can use Navigation.PushAsync in xaml.cs

but I can not use App.Current.MainPage.Navigation.PushAsync in other cs file.

I am using simple xamarin.forms not shell. add a tabbed page to the mainpage.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered

Hello,

Welcome to Microsoft Q&A!

How to access PushAsync in cs file not the xmal.cs?

Definitely we can call App.Current.MainPage.Navigation.PushAsync anywhere in project .

But first of all , we should put the App.Current.MainPage into navigation stack , in other word , the MainPage should be wrapped into NavigationPage .

Normally the solution is to set NavigationPage in App.cs , MainPage = new NavigationPage(new TabbedPage1()); .

However , if you just want TabbedPage to be the root page , you can use (App.Current.MainPage as TabbedPage).CurrentPage.Navigation.PushAsync(xxx); (CurrentPage should be placed in naviagtion stack as well).


Best Regards,
Cole Xia


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.