0

I have New Department Form page I create Department, 10 Employee gets created On list On Click Employee, Details get fire with below script

I get PushAsyn is not supported globally on Android, please use a Nagigation page But this works if I go all the way back to Department page and come to list and click on details On create

async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
    {
        var item = args.SelectedItem as Employee;
        if (item == null)
            return;
         //None below works
         await (App.Current.MainPage).Navigation.PushAsync(new EmployeeDetail(item));
        //await Navigation.PushAsync(new EmployeeDetail(item));
        //Application.Current.MainPage = new NavigationPage(new EmployeeDetail(item));

    }
FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • Are you using a MasterDetailPage setup? From what I understand by the error you do not have a navigation page instance in the MainPage property. – FreakyAli May 11 '20 at 01:58
  • Thanks Ali, I dont have a Master page, My Set, I have a Create Page/xmal, Create Page Creates in viewmodel then auto navigates to Displaye record page, Its a List with Items, On Display page its a List with Item clicked gives the error to go to details to be entered... – Robert Cohen May 11 '20 at 04:01
  • Department Page is Entry Form, Form filled, Submit goes to Displays page with the List, each Item on list clicable to go detail page, thats where the error.. – Robert Cohen May 11 '20 at 04:02
  • If the below answer does not work for you let me know and i can add a solution! – FreakyAli May 11 '20 at 06:24
  • I have this on my App page, How can I declare second main page on my App `public App() { MainPage = new LoginPage(); }` – Robert Cohen May 12 '20 at 14:58
  • Example below not usefull for me at this stage, Its not shell App as well. No menu on top and 2 page navigation. My problem is 3 page navigation and I lose the hamburger menu and I dont get arrow up top to go back. May be I try this on second page where list Application.Current.MainPage.Navigation.PushAsync(new DisplayPage(id)); and await Navigation.PushAsync(new itemDetail(item)); when it get clicked – Robert Cohen May 12 '20 at 15:07
  • Could you refer my answer here and compare your code? https://stackoverflow.com/questions/49169049/hamburger-menu-xamarin-forms-masterdetailpage – FreakyAli May 12 '20 at 18:27
  • Thanks FreakyAli, Appriciated this link.. Seems like Application.Current.MainPage.Navigation.PushAsync(new DisplayPage(id)); and await Navigation.PushAsync(new ItemDetails(item)); second Page and third page await Navigation.PopAsync(); will do the trick – Robert Cohen May 12 '20 at 21:00
  • Sounds great do you want me to add that as answer for others who have the same question? – FreakyAli May 12 '20 at 23:08

1 Answers1

0

According to your description, if you want to use navigation between ContentPages. There are two way to navigate vetween COntentPages, one is using Navigation.PushAsync(), another is using Navigation.PushModalAsync().

If you use Navigation.PushAsync(), please set navigation page instance for the MainPage property in App.xaml.cs constructor.

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

    }

Then you can use the following code to navigation.

private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        Employee item = e.SelectedItem as Employee;
        if(item!=null)
        {
            Navigation.PushAsync(new Page21(item));

        }
    }

if you don't create navigation instance for MainPage property in App.xaml.cs,

public App()
{
    InitializeComponent();         
    MainPage = new Page20(); 

}

You need

 private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        Employee item = e.SelectedItem as Employee;
        if(item!=null)
        {          
            Navigation.PushModalAsync(new Page21(item));
        }
    }

More detailed info about Xamarin.Forms Modal Pages, please take a look:

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/modal

Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
  • I dont understand this Cheery BU.. this what I have in my app public App() `{ MainPage = new LoginPage(); }` Goes to login page with LoginviewModel, Successfull login, Open the Shell Menu.Where Click on New. Starts 3 page operation. 1st page is Form, filled. On submit.. Navigate to 2 page with List of Created record attributes. Click on list show each attributes on 3rd page. 2nd page on, list, click on gives error.. – Robert Cohen May 12 '20 at 14:56