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