Reputation: 61
I am calling common page which lists all distributors. when I select Item from list, I want to show next page based on from where List Page is called.
In Short calling ListPage from Page A, Page B and Page C.
Just can't determine my previous page/ can I use this.Parent
method? how?
Upvotes: 0
Views: 2006
Reputation: 701
I'm new to Xamarin and was having a similar problem. What helped me was using the Count and Item[Int32] properties of the ModalStack, but NavigationStack is also of type IReadOnlyList and has the same properties. So maybe something like:
var previousPageIndex = Navigation.NavigationStack.Count - 2;
var previousPageType = Navigation.NavigationStack[previousPageIndex];
if (previousPageType.Equals(Xamarin.Forms.NavigationPage)) {
Navigation.pushAsync(Page1);
} else if (previousPageType.Equals(PROJECT.DIR.CustomNavigationPage)) {
Navigation.pushAsync(Page2);
}
NOTE: Checking previousPageType
doesn't help if you're getting to your current page from 2 different pages of the same type. In my actual scenario, I was either in a ModalStack or not, so I just had to check if ModalStack.Count > 0
to determine whether to pop back a page or to switch tabs.
Upvotes: 1
Reputation: 61
Got the work around as passing parameter to main ContentPage's class constructor with default value. Assigning that value to class field and checking with it. Please let me know if anyone has better solution :)
class DistributorListX : ContentPage
{
public string previousPage;
public DistributorListX(string PreviousPage="")
{
InitializeComponent();
previousPage = PreviousPage;
}
void listItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (previousPage=="A")
Navigation.PushAsync(A1);
else
Navigation.PushAsync(A2);
}
}
Upvotes: 0