As is known to all, UWP programs are a set of code that can run on different platforms. But different devices must be unique, so for these unique things, you have to use "unique code" to deal with.
So Microsoft provides a range of expansion libraries to implement this special processing.
As shown in the red box, expand the assembly.
Of course, after the mobile phone back key processing, we need to add the mobile corresponding assembly to our project.
After adding only a short piece of code, we can implement the Back button processing. The code is simple.
if("Windows.mobile"==Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily) Windows.Phone.UI.Input.HardwareButtons. Backpressed+=hardwarebuttons_backpressed;Private voidHardwarebuttons_backpressed (Objectsender, Windows.Phone.UI.Input.BackPressedEventArgs e) { varRootframe = Window.Current.Content asFrame; if(rootframe.cangoback) {rootframe.goback (); E.handled=true; }}
If used to determine the platform on which the program runs, if it is a moblie, register an event to handle the back. If you do not judge, the compilation will not be error, but the running
Error will occur.
So where does this piece of code fit in?
I've always been in the constructor of a single page, but later found that there was a problem with the increase in the number of pages. So now I'm going to put this code in App.cs, and let it register only once for the entire life of the program.
[UWP Dev] handles phone fallback events