Three ways to set up a specific device UWP XAML view

Source: Internet
Author: User

Developers can set up UWP-specific devices for XAML view, desktop, Mobile, Iot, which is useful for setting up different screens for different devices. We can use Relativepanel,visualstatetriggers, but our XAML is very large, and when we do it we feel like we're going to have to modify something to make sure we delete it all. To allow us to use different XAML view on different devices, we can do this in the following ways:
Display different background colors, text, in the same XAML, start page on different devices

New Folder Devicefamily-type

The type inside is our device, Mobile: Mobile, Desktop: Desktop,iot
Create a new folder in our solution, where we are mobile

We are building new devicefamily-mobile new Xaml,mainpage

New Class MainPage

If you are running on your phone, you will use Devicefamily-mobile/mainpage.xaml, and if so, you will use the solution Devicefamily/mainpage.xaml

In the XAML file plus. Devicefamily-type

The second way in the XAML file is Add. Devicefamily-type, we create a new xaml,mainpage.devicefamily-mobile.xaml.

We cannot use methods 1 and 2 in a project.
We'll turn on Mobil and use Mainpage.devicefamily-mobile.xaml.

InitializeComponent overloading

Add a Devicefamily-type folder write a XAML in the Mainpage.g.i.cs to InitializeComponent overload.

 Public voidInitializeComponent (Global:: System.UriResourcelocator) {if(_contentloaded)return; _contentloaded= true;if(Resourcelocator== NULL) {Resourcelocator= New Global:: System.Uri("Ms-appx:///mainpage.xaml"); }Global:: Windows.UI.Xaml.Application.LoadComponent(This, Resourcelocator,Global:: Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);}

You can specify a URI to require XAML

publicMainPage()  {    if"Windows.Mobile")    {        if (usePrimary)        {            InitializeComponent(new Uri("ms-appx:///PrimaryMainPage.xaml", UriKind.Absolute));        }        else        {            InitializeComponent(new Uri("ms-appx:///SecondaryMainPage.xaml", UriKind.Absolute));        }    }    else    {        InitializeComponent();    }}

Use devicefamily to specify the effect of the view, first the mainpage.xaml of the desktop

We use different colors on Mobil

If using mode 3, we need to manually write in main we need to load, we have two XAML

Single page Trigger
We can use different XAML on one page for different devices
Windowsstatetriggers devicefamily Sample

Https://github.com/igrali/UWP-DeviceFamily

Http://www.cnblogs.com/mushroom/p/5080032.html

http://igrali.com/2015/08/02/three-ways-to-set-specific-devicefamily-xaml-views-in-uwp/

Three ways to set up a specific device UWP XAML view

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.