背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸
作者:webabcd
介绍
背水一战 Windows 10 之 UI
- 窗口全屏
- 窗口尺寸
示例
1、窗口全屏
UI/FullScreen.xaml
<Page
x:Class="Windows10.UI.FullScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <TextBlock Name="lblMsg" Margin="0 10 0 0" /> <Button Name="btnFullScreen" Content="全屏/取消全屏" Click="btnFullScreen_Click" Margin="0 10 0 0" /> <Button Name="btnShowStandardSystemOverlays" Content="在全屏状态下,显示系统 UI,比如标题栏和任务栏" Click="btnShowStandardSystemOverlays_Click" Margin="0 10 0 0" /> <CheckBox Name="chkFullScreenSystemOverlayMode" Content="全屏状态下的,系统边缘手势的响应模式 unchecked:FullScreenSystemOverlayMode.Standard, checked:FullScreenSystemOverlayMode.Minimal" Click="chkFullScreenSystemOverlayMode_Click" Margin="0,10,0,0" /> <CheckBox Name="chkPreferredLaunchWindowingMode" Content="窗口的启动模式 unchecked:ApplicationViewWindowingMode.Auto, unchecked:ApplicationViewWindowingMode.FullScreen" Click="chkPreferredLaunchWindowingMode_Click" Margin="0,10,0,0" /> </StackPanel>
</Grid>
</Page>
UI/FullScreen.xaml.cs
/*
* 演示“窗口全屏”相关知识点
*
* ApplicationView - 用于操作窗口以及获取窗口信息
* GetForCurrentView() - 返回 ApplicationView 实例
*/ using Windows.System;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation; namespace Windows10.UI
{
public sealed partial class FullScreen : Page
{
private MainPage _rootPage; public FullScreen()
{
this.InitializeComponent(); this.Loaded += FullScreen_Loaded;
} private void FullScreen_Loaded(object sender, RoutedEventArgs e)
{
/*
* ApplicationView.PreferredLaunchWindowingMode - 窗口的启动模式
* Auto - 系统自动决定
* PreferredLaunchViewSize - 由 ApplicationView.PreferredLaunchViewSize 决定(参见:UI/ScreenSize.xaml)
* FullScreen - 全屏启动
*
* ApplicationView.GetForCurrentView().FullScreenSystemOverlayMode - 全屏状态下的,系统边缘手势的响应模式
* Standard - 标准方式。比如鼠标移动到顶端显示标题栏,移动到底端显示任务栏
* Minimal - 最小方式。比如鼠标移动到顶端显示一个小的临时 UI,移动到底端显示一个小的临时 UI,点击这个临时 UI 时再显示标题栏或任务栏
*/ // unchecked:FullScreenSystemOverlayMode.Standard, checked:FullScreenSystemOverlayMode.Minimal
chkFullScreenSystemOverlayMode.IsChecked = ApplicationView.GetForCurrentView().FullScreenSystemOverlayMode == FullScreenSystemOverlayMode.Minimal; // unchecked:ApplicationViewWindowingMode.Auto, unchecked:ApplicationViewWindowingMode.FullScreen
chkPreferredLaunchWindowingMode.IsChecked = ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen;
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
_rootPage = MainPage.Current;
_rootPage.KeyDown += _rootPage_KeyDown;
} protected override void OnNavigatedFrom(NavigationEventArgs e)
{
_rootPage.KeyDown -= _rootPage_KeyDown;
} private void _rootPage_KeyDown(object sender, KeyRoutedEventArgs e)
{
// 判断是否按下了 escape 键
if (e.Key == VirtualKey.Escape)
{
var view = ApplicationView.GetForCurrentView();
if (view.IsFullScreenMode)
{
// 退出全屏状态
view.ExitFullScreenMode();
}
}
} private void btnFullScreen_Click(object sender, RoutedEventArgs e)
{
ApplicationView view = ApplicationView.GetForCurrentView();
// 判断当前是否是全屏模式
if (view.IsFullScreenMode)
{
// 退出全屏模式
view.ExitFullScreenMode();
lblMsg.Text = "退出全屏模式";
}
else
{
// 尝试进入全屏模式
bool isSuccess = view.TryEnterFullScreenMode();
if (isSuccess)
{
lblMsg.Text = "进入全屏模式";
}
else
{
lblMsg.Text = "尝试进入全屏模式失败";
}
}
} private void btnShowStandardSystemOverlays_Click(object sender, RoutedEventArgs e)
{
ApplicationView view = ApplicationView.GetForCurrentView();
// 在全屏状态下,是否显示系统 UI,比如标题栏和任务栏
view.ShowStandardSystemOverlays();
} private void chkFullScreenSystemOverlayMode_Click(object sender, RoutedEventArgs e)
{
ApplicationView view = ApplicationView.GetForCurrentView();
view.FullScreenSystemOverlayMode = chkFullScreenSystemOverlayMode.IsChecked.Value ? FullScreenSystemOverlayMode.Minimal : FullScreenSystemOverlayMode.Standard;
} private void chkPreferredLaunchWindowingMode_Click(object sender, RoutedEventArgs e)
{
ApplicationView.PreferredLaunchWindowingMode = chkPreferredLaunchWindowingMode.IsChecked.Value ? ApplicationViewWindowingMode.FullScreen : ApplicationViewWindowingMode.Auto;
}
}
}
2、窗口尺寸
UI/ScreenSize.xaml
<Page
x:Class="Windows10.UI.ScreenSize"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <TextBlock Name="lblMsg" Margin="0 10 0 0" /> <Button Name="btnChangeSize" Content="尝试改变窗口大小" Click="btnChangeSize_Click" Margin="0 10 0 0" /> </StackPanel>
</Grid>
</Page>
UI/ScreenSize.xaml.cs
/*
* 演示“窗口尺寸”相关知识点
*
* ApplicationView - 用于操作窗口以及获取窗口信息
* GetForCurrentView() - 返回 ApplicationView 实例
*/ using Windows.Foundation;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Windows10.UI
{
public sealed partial class ScreenSize : Page
{
public ScreenSize()
{
this.InitializeComponent(); this.Loaded += ScreenSize_Loaded;
} private void ScreenSize_Loaded(object sender, RoutedEventArgs e)
{
// Window.Current.Bounds - 当前窗口的大小(单位是有效像素,没有特别说明就都是有效像素)
// 注:窗口大小不包括标题栏,标题栏属于系统级 UI
lblMsg.Text = string.Format("window size: {0} * {1}", Window.Current.Bounds.Width, Window.Current.Bounds.Height); ApplicationView applicationView = ApplicationView.GetForCurrentView(); // SetPreferredMinSize(Size minSize) - 指定窗口允许的最小尺寸(最小:192×48,最大:500×500)
applicationView.SetPreferredMinSize(new Size(, )); // PreferredLaunchViewSize - 窗口启动时的初始尺寸
// 若要使 PreferredLaunchViewSize 设置有效,需要将 ApplicationView.PreferredLaunchWindowingMode 设置为 ApplicationViewWindowingMode.PreferredLaunchViewSize
ApplicationView.PreferredLaunchViewSize = new Size(, );
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; /*
* ApplicationView.PreferredLaunchWindowingMode - 窗口的启动模式
* Auto - 系统自动调整
* PreferredLaunchViewSize - 由 ApplicationView.PreferredLaunchViewSize 决定
* FullScreen - 全屏启动
*/
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
// 窗口尺寸发生变化时触发的事件
Window.Current.SizeChanged += Current_SizeChanged;
} protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Window.Current.SizeChanged -= Current_SizeChanged;
} private void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
lblMsg.Text = string.Format("window size: {0} * {1}", e.Size.Width, e.Size.Height);
} private void btnChangeSize_Click(object sender, RoutedEventArgs e)
{
ApplicationView applicationView = ApplicationView.GetForCurrentView(); Size size = new Size(, ); // TryResizeView(Size value) - 尝试将窗口尺寸设置为指定的大小
bool success = applicationView.TryResizeView(size);
if (success)
{
lblMsg.Text = "尝试修改窗口尺寸成功";
}
else
{
lblMsg.Text = "尝试修改窗口尺寸失败";
} // 注:怎么修改窗口的显示位置呢?暂时不知道
}
}
}
OK
[源码下载]
背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸的更多相关文章
- 背水一战 Windows 10 (4) - UI: 多窗口
[源码下载] 背水一战 Windows 10 (4) - UI: 多窗口 作者:webabcd 介绍背水一战 Windows 10 之 UI 多窗口 示例1.自定义帮助类,用于简化 Secondary ...
- 背水一战 Windows 10 (5) - UI: 标题栏
[源码下载] 背水一战 Windows 10 (5) - UI: 标题栏 作者:webabcd 介绍背水一战 Windows 10 之 UI 标题栏 示例TitleBarDemo.xaml <P ...
- 背水一战 Windows 10 (2) - UI: 概述, 启动屏幕, 屏幕方向
[源码下载] 背水一战 Windows 10 (2) - UI: 概述, 启动屏幕, 屏幕方向 作者:webabcd 介绍背水一战 Windows 10 之 UI UI 设计概述 启动屏幕(闪屏) 屏 ...
- UI: 窗口全屏, 窗口尺寸
窗口全屏 窗口尺寸 示例1.窗口全屏UI/FullScreen.xaml <Page x:Class="Windows10.UI.FullScreen" xmlns=&quo ...
- 背水一战 Windows 10 (8) - 控件 UI: StateTrigger
[源码下载] 背水一战 Windows 10 (8) - 控件 UI: StateTrigger 作者:webabcd 介绍背水一战 Windows 10 之 控件 UI VisualState 之 ...
- 背水一战 Windows 10 (113) - 锁屏: 将 Application 的 Badge 通知和 Tile 通知发送到锁屏, 将 secondary tile 的 Badge 通知和 Tile 通知发送到锁屏
[源码下载] 背水一战 Windows 10 (113) - 锁屏: 将 Application 的 Badge 通知和 Tile 通知发送到锁屏, 将 secondary tile 的 Badge ...
- 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI
[源码下载] 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI 作者:webabcd 介绍背水一战 Wind ...
- 背水一战 Windows 10 (6) - 控件 UI: 字体的自动继承的特性, Style, ControlTemplate
[源码下载] 背水一战 Windows 10 (6) - 控件 UI: 字体的自动继承的特性, Style, ControlTemplate 作者:webabcd 介绍背水一战 Windows 10 ...
- Windows中检测当前是否有窗口全屏
不时看到有人问起如何判断当前是否有窗口正处于全屏状态? 不过, 在解决这个问题之前先来解决一个简单的问题? 什么是全屏? 相当一部分人认为: 窗口如果是最大化的, 那么它就是最 ...
随机推荐
- IOS Socket 01-网络协议基础知识
1. 网络参考模型 OSI参考模型 TCP/IP参考模型 2. 七层简述 1)物理层:主要定义物理设备标准,如网线的接 ...
- 手打的笔记,java语法中的输入输出,语句,及注释。
手打的笔记: () 内的则为注意事项或者提示 public static void main (String[] args) ******(用一个方法)****{ int i = 10; int j ...
- Lua 协程coroutine
协程和一般多线程的区别是,一般多线程由系统决定该哪个线程执行,是抢占式的,而协程是由每个线程自己决定自己什么时候不执行,并把执行权主动交给下一个线程. 协程是用户空间线程,操作系统其存在一无所知,所以 ...
- JS 脚本最后加载
有些脚本执行,为了不影响页面其他脚本执行,需要放在最后 <script type="text/javascript"> function addLoadEvent(fu ...
- EXCEL的导出
具体实现代码: protected void EXCEL_Click(object sender, EventArgs e) { ToExcel(GridView1); } public void T ...
- iOS---------- @synchronized(self)的用法
1. synchronized 这个主要是考虑多线程的程序,这个指令可以将{ } 内的代码限制在一个线程执行,如果某个线程没有执行完,其他的线程如果需要执行就得等着. Objective-C除了提 ...
- iOS开发——高级技术OC篇&运行时(Runtime)机制
运行时(Runtime)机制 本文将会以笔者个人的小小研究为例总结一下关于iOS开发中运行时的使用和常用方法的介绍,关于跟多运行时相关技术请查看笔者之前写的运行时高级用法及相关语法或者查看响应官方文档 ...
- Java 集合系列目录(Category)
下面是最近总结的Java集合(JDK1.6.0_45)相关文章的目录. 01. Java 集合系列01之 总体框架 02. Java 集合系列02之 Collection架构 03. Java 集合系 ...
- php基础教程-变量
变量来源于数学,是计算机语言中能储存计算结果或能表示值抽象概念.变量可以通过变量名访问.在指令式语言中,变量通常是可变的:但在纯函数式语言(如Haskell)中,变量可能是不可变(immutable) ...
- 新版本来袭:Apache Spark 1.5新特性介绍
年9月9日发布了1.5版本,该版本由230+开发人员和80+机构参与,修复了1400多个补丁,该版本可以通过 http://spark.apache.org/downloads.html进行下载.Sp ...