Reputation: 540
I'm trying to write a windows phone application and am wondering if it's possible to have a software button in the UI that does the same thing as the hardware back button (just sends a system back command). I can't seem to find any information on how to do this online.
Upvotes: 0
Views: 42
Reputation: 2621
try this:
XAML:
<Button x:Name="btnBack" Content="Back" Click="btnBack_Click"></Button>
CS:
private void btnBack_Click(object sender, RoutedEventArgs e)
{
if (NavigationService.CanGoBack)
NavigationService.GoBack();
else
App.Current.Terminate();
}
This would work as same Back button. if any back-state is there it would go to that state or if not it would close (Terminate) the Application.
Upvotes: 1
Reputation: 45
you can override the back button function
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
//Do your work here
base.OnBackKeyPress(e);
}
Upvotes: 0