Reputation: 611
How do I navigate to a specific page with a particular condition? For example if I click the back button and the previous page is the store page, then navigate to the page store, whereas if the previous page is another page, the page to the home page. I tried the code below but it did not work:
private void backButton_Click(object sender, RoutedEventArgs e)
{
if (this.Frame.Navigate(typeof(Store)) == true)
{
this.Frame.Navigate(typeof(Store));
}
else
{
this.Frame.Navigate(typeof(MainPage));
}
}
Upvotes: 0
Views: 139
Reputation: 3221
You have to make use of BackStack
List of frame
var frame = Window.Current.Content as Frame;
if (frame != null)
{
var lastPage = frame.BackStack.LastOrDefault();
if (lastPage != null && lastPage.SourcePageType.Equals(typeof(Store)))
{
}
}
Upvotes: 2