UWP 适配不同设备 屏幕
1、DeviceFamily-Type文件夹
将Index.xaml拷贝到DeviceFamily-Desktop 和DeviceFamily-Mobile,删除这2个目录下的Index.xmal.cs 文件。
2、DeviceFamily-Type扩展
通过创建新的XAML视图达到同样的效果,使用同样的名称,但是DeviceFamily-Type是扩展的。比如MainPage页面,它意思是添加一个新的XAML视图文件叫MainPage.DeviceFamily-Mobile.xaml,它放在和MainPage同样的文件夹。
3、InitializeComponent重载
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(); } }
4、VisualStateManager
<VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="VisualStateGroup"> <VisualState x:Name="Narrow"> <VisualState.StateTriggers> <AdaptiveTrigger MinWindowWidth="0" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="tabLayout.(Grid.Column)" Value="1" /> <Setter Target="tabLayout.(Grid.Row)" Value="1" /> <Setter Target="pivot.(Grid.Column)" Value="1" /> <Setter Target="pivot.(Grid.Row)" Value="0" /> <Setter Target="tabLayout.Orientation" Value="Horizontal" /> <Setter Target="tabLayout.Width" Value="Auto" /> </VisualState.Setters> </VisualState> <VisualState x:Name="Wide"> <VisualState.StateTriggers> <AdaptiveTrigger MinWindowWidth="501" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="tabLayout.(Grid.Column)" Value="0" /> <Setter Target="tabLayout.(Grid.Row)" Value="0" /> <Setter Target="pivot.(Grid.Column)" Value="1" /> <Setter Target="pivot.(Grid.Row)" Value="0" /> <Setter Target="tabLayout.Orientation" Value="Vertical" /> <Setter Target="tabLayout.Width" Value="60" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups>
原文出处
http://www.cnblogs.com/kiminozo/p/4738355.html
http://www.cnblogs.com/mushroom/p/5080032.html
相关推荐
86523296 2020-04-22
VanTYS 2020-02-23
Yyqingmofeige 2019-12-01
89433869 2014-03-29
bigname 2012-05-29
rkhstar 2013-09-02
chaochao 2009-08-05
yangtjh 2009-05-23
sapcefish 2011-02-22
小鑫 2009-12-25
yixiaof 2007-07-31
Pinapps 2018-04-02
私宅 2018-02-06
简单心理 2018-01-20
小道消息 2018-01-15
锦妖和她的小伙伴们 2017-12-25
锦妖和她的小伙伴们 2017-12-10
故事中的故事TaleofTales 2017-11-28