当前位置:网站首页>三种方式设置特定设备UWP XAML view
三种方式设置特定设备UWP XAML view
2022-08-04 20:51:00 【林德熙】
开发者可以设置UWP特定设备xaml view,在桌面,手机,Iot,这个对于设置对不同设备的不同屏幕有用。我们可以使用RelativePanel,VisualStateTriggers,但是这样我们的xaml很大,我们在弄的时候觉得想修改一个东西会让我们把全部删了。 为了让我们可以在不同设备使用不同xaml view,我们可以有下面的方式:
在不同设备显示不同背景颜色,文本,在同xaml,开始的页面
新建文件夹DeviceFamily-Type
里面的type是我们的设备,手机:Mobile,桌面:Desktop,IOT
在我们的解决方案新建一个文件夹,我们这里在手机Mobile
我们在新建DeviceFamily-Mobile新建xaml,MainPage
新建类MainPage
如果在手机运行,就会使用DeviceFamily-Mobile/MainPage.xaml,如果是其他,就会使用解决方案DeviceFamily/MainPage.xaml
在xaml文件加.DeviceFamily-Type
第二种方式在xaml文件加.DeviceFamily-Type,我们创建一个新的xaml,MainPage.DeviceFamily-Mobile.xaml
我们不能使用方法1和2在一个工程。
我们打开mobil会使用MainPage.DeviceFamily-Mobile.xaml
InitializeComponent重载
添加一个DeviceFamily-Type文件夹在里面写一个xaml会在MainPage.g.i.cs对InitializeComponent重载。
public void InitializeComponent(global::System.Uri resourceLocator)
{
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);
}可以指定一个uri到需要xaml
public MainPage()
{
if (AnalyticsInfo.VersionInfo.DeviceFamily == "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();
}
}使用DeviceFamily指定视图的效果,首先是桌面的MainPage.xaml
我们使用不同颜色放在mobil
如果使用方式3,我们需要手动在main写我们需要加载,我们有两个xaml
单页面触发器
我们可以在一个页面不同设备使用不同的xaml 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/
边栏推荐
猜你喜欢
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库

工龄10年的测试员从大厂“裸辞”后...

After the tester with 10 years of service "naked resignation" from the big factory...

使用 Allatori 进行 Jar 包混淆

3、IO流之字节流和字符流

零知识证明笔记——私密交易,pederson,区间证明,所有权证明

Retrofit的使用及原理详解

无代码平台字段设置:基础设置入门教程

LINQ to SQL (Group By/Having/Count/Sum/Min/Max/Avg操作符)

使用百度EasyDL实现森林火灾预警识别
随机推荐
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
win10 uwp 使用 ScaleTransform 放大某个元素
KubeSphere简介,功能介绍,优势,架构说明及应用场景
如何用好建造者模式
About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
Tensorflow2 环境搭建
【Web漏洞探索】跨站脚本漏洞
知识分享|如何设计有效的帮助中心,不妨来看看以下几点
adb控制常用命令
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
idea源码无法下载
新式茶饮,卷完水果还能卷什么?
Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格
刷题-洛谷-P1304 哥德巴赫猜想
Nuxt.js的优缺点和注意事项
ts集成和使用
【TypeScript】深入学习TypeScript枚举
Win10 uwp use ScaleTransform magnify an element
Debug locally and start the local server in vs code