I want to handle the windows phone's back button event on several of my pages differently. My app's pages are hierarchically ordered and instead of exiting the app itself (what only should be possible on the hierarchical uppermost page => also known as home page) I want to navigate to the hierarchical upper-next page.
Hierarchical navigation:
WP Main Menu > App Home Menu > App Page#1 > App Page#2 > ...
I already defined a related method for handling the back button press but I can't seem to be able to register the handler within the page's constructor accordingly, and there are no related C++/CX guides out there!
private:
void Page::HardwareBackButtonPressed(Platform::Object^ sender,
Windows::Phone::UI::Input::BackPressedEventArgs^ e)
{
e->Handled = true;
if (Frame->CanGoBack == true)
Frame->GoBack();
else
Frame->Navigate(MainPage::typeid, safe_cast<Platform::Object^>(0));
}
The registration of the handler looks like this (seems to be invalid)
HardwareButtons::BackPressed += ref new Windows::Foundation::EventHandler<BackPressedEventArgs^>(
this, &HardwareBackButtonPressed);
I'm not even sure if this is the right way to go.