[UWP Dev] handles phone fallback events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.