[c#][Windows 10 | Windows 10 mobile]UWP自适应UI——VisualStateManager
来源:互联网 发布:金刚经 知乎 编辑:程序博客网 时间:2024/05/20 16:10
在新的UWP中,写一份代码即可将应用在多种不同的分辨率上运行,那么怎么去自适应各种大小的UI,我们可以采用VisualStateManager。
目标:实现以下界面
我们先在xaml的根Grid中。写两个Grid,分别是第一页和第二页
<Grid><Grid.ColumnDefinitions><ColumnDefinition Width="auto"/> <ColumnDefinition /> </Grid.ColumnDefinitions><Grid x:Name="redgrid" Grid.Column="0"/><Grid x:Name="yellowgrid" Grid.Column="1"/></Grid>
然后我们有两种方式,一种是打开Blend,另一种是通过代码的方式,初学者可以用Blend熟悉下VisualStateManager的使用方法
在Blend中,,在状态页面添加VisualStateGroup,在VisualStateGroup内添加两个VisualState。
之后我们先选择小UI,在“对象和时间线”窗口中将yellowgrid的Visiblity设置为Collapsed,既在小页面中将第二页隐藏。
然后返回Visual Studio,我们发现Blend已经帮我们添加了一段代码
<VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="VisualStateGroup"><VisualState x:Name="VisualState000"><VisualState.Setters> <Setter Target="yellowgrid.(FrameworkElement.Visibility)" Value="Collapsed"/> </VisualState.Setters> </VisualState> <VisualState x:Name="VisualState750"> </VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups>
接下来我们设置下对UI的选择
在对应页面的构造函数中
this.SizeChanged += (s, e) =>{var state = "VisualState000"; if (e.NewSize.Width > 000 && e.NewSize.Width < 750) { } if (e.NewSize.Width > 750) { state = "VisualState750"; } VisualStateManager.GoToState(this, state, true);};
之后,在小UI的页面跳转时,记得显示刚才隐藏的第二页,在返回上一页的时候再次隐藏第二页,即可实现对UI的自适应
1 0
- [c#][Windows 10 | Windows 10 mobile]UWP自适应UI——VisualStateManager
- Windows 10 Mobile(UWP)蓝牙开发
- Windows 10 UWP/Windows 10 Mobile GIF图片显示
- Windows 10 UWP/Windows 10 Mobile 的微博分享实现
- Windows 10 UWP 新内容
- Windows 10 UWP控件简述
- windows mobile 自适应分辨率
- Windows mobile UI
- Windows Mobile UI 设计
- Windows 10 UWP页面跳转and传值
- 初识Windows 10 UWP Background Task
- iPhone UI in Windows Mobile
- [c#][Windows 10 | Windows 10 mobile | Windows Phone] HttpClient 实现form-data POST上传请求
- Windows Mobile下界面自适应输入法状态
- Windows Mobile 下 自适应大小的 Label
- Windows mobile应用程序自适应屏幕大小
- 适用于 Windows Mobile 的自适应应用程序
- Windows Mobile下界面自适应输入法状态
- LeetCode [Add Dighits]
- 如何安装win10、ubuntu15.10双系统?
- 线程中断Thread.interrupt()的用法
- python对文件进行读写
- 彩色的大三
- [c#][Windows 10 | Windows 10 mobile]UWP自适应UI——VisualStateManager
- 石头剪刀布游戏
- 欢迎使用CSDN-markdown编辑器
- 淘宝内部分享:怎么跳出MySQL的10个大坑
- HTML媒体
- C++调用python:无参数,简单helloworld示例
- 程序员必读书单
- 地理位置输入提示(不显示地图)
- dubbo+zookeeper实现分布式调用