Reputation: 8531
I'm using a new item Basic Template with the app name and back button. It is being used inside of a "Blank" project.
However, the back button is not responding to touch events.
This following is code that was generated. The back button just disappears.
<Button x:Name="backButton" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}" Click="GoBack"/>
I even tried making my own Click Handle and tried navigating myself with.
this.Frame.Navigate(typeof(MainPage));
However that isn't working either. Probably due to something that auto generated because I can create a button myself and wire it up for that (so I'm really trying to stick with the Templates).
Any ideas please?
Edit: I found it really odd none of the Navigation is working. After drilling some more it appears to be something with LayoutAwarePage. I'm missing something here. Will post updates.
Edit: Sorry about that. I added the event click listeners back in (I must have removed that copying around). However that still does not fix my issue. I tried setting the back button to the "GoBack" function and when you hit the back button it just disappears. I also tried creating my own method and trying to navigate myself and still did not work.
Upvotes: 1
Views: 8844
Reputation: 11
Im making my back buttons like this:
XAML code. In this case LoginPage.xaml.
<Button x:Name="ButtonGoBack" Click="ButtonGoBack_OnClick" Style="{StaticResource NavigationBackButtonNormalStyle}"/>
C# code in LoginPage.xaml.cs
private void ButtonGoBack_OnClick(object sender, RoutedEventArgs e)
{
this.Frame.GoBack();
}
Upvotes: 1
Reputation: 770
If you used
Frame.SetNavigationState("1,0");
you removed the back stack entry , so the back button will not working .
Upvotes: 0
Reputation: 152
This happened to me too. I know nothing could've changed in my code so I checked the project properties. In Common Properties->References I noticed an anomaly, there have been some resources that was never there, ( all I should have in that project is SQLite for Windows RunTime). I then deleted the unwanted resource and fixed the navigation problem.
Upvotes: 0
Reputation: 1
I've just had the same issue as Frank. I found my problem to be that I overrided the OnNavigatedTo handler without calling the base class's (LayoutAwarePage) handler also. This meant LayoutAwarePage wasn't setting its _pageKey member variable which it uses in its OnNavigatedFrom handler.
Hope this helps others with the same issue.
Upvotes: 0
Reputation: 8852
You need an Click
event handler on the button. Click="GoBack"
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
GoBack
function is available in LayoutAwarePage
which is most likely the base class of your page, if not make sure it is. LayoutAwarePage
class resides inside Project\Common
Upvotes: 4
Reputation: 31813
Well, this approach appears to take code from the Basic page. Could you confirm that you are inheriting from LayoutAwarePage and not from Page? Otherwise GoBack is not implemented in this way. Also, you cannot GoBack if you have not navigated from this page in the first place, from another. And, finally (just brainstorming here), you cannot GoBack if you got to this page by setting the Frame itself and not the page (in the previous location). This would clear the navigation history.
And, also, can you confirm this does not work?
this.Frame.GoBack();
Best of luck!
Upvotes: 1
Reputation: 1384
You should not need to write any of your own code to enable the back button, as it ties into the underlying navigation framework automatically. If there is a page in the back stack to navigate to, the back button will be enabled.
What you are missing, from what I can see, is that if you start your app on the Basic page that you added, there's nothing in the back stack of the navigation framework for you to navigate to.
I tested your scenario using the following steps:
Double-clicked the button, and added the following code to the click event handler:
this.Frame.Navigate(typeof(BasicPage1));
Ran the project, and the back button worked as expected.
Upvotes: 2
Reputation: 16826
From the XAML markup that I see, there is no Click
event handler tied to the button, so no action is taken unless you hook it to one.
Upvotes: 2