Windows 10 (3) and Windows 10
[Download source code]
Backwater world war I Windows 10 (3)-UI: full screen window, window size
Author: webabcd
Introduction
UI of Windows 10
- Window full screen
- Window Size
Example
1. Full Screen Window
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 = "full screen / cancel full screen" Click = "btnFullScreen_Click" Margin = "0 10 0 0" />
<Button Name = "btnShowStandardSystemOverlays" Content = "In full screen, display system UI, such as title bar and taskbar" 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 = "The launch mode of the window unchecked: ApplicationViewWindowingMode.Auto, unchecked: ApplicationViewWindowingMode.FullScreen" Click = "chkPreferredLaunchWindowingMode_Click" Margin = "0,10,0,0" />
</ StackPanel>
</ Grid>
</ Page>
UI/FullScreen. xaml. cs
/ *
* Demonstrate knowledge about "window full screen"
*
* ApplicationView-used to manipulate windows and get window information
* GetForCurrentView ()-returns ApplicationView instance
* /
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-the window's launch mode
* Auto-the system determines automatically
* PreferredLaunchViewSize-determined by ApplicationView.PreferredLaunchViewSize (see: UI / ScreenSize.xaml)
* FullScreen-Full Screen Launch
*
* ApplicationView.GetForCurrentView (). FullScreenSystemOverlayMode-Response mode of system edge gestures in full screen state
* Standard-Standard method. For example, move the mouse to the top to display the title bar, and move to the bottom to display the task bar.
* Minimal-the smallest way. For example, move the mouse to the top to display a small temporary UI, move to the bottom to display a small temporary UI, and click the temporary UI to display the title bar or task bar.
* /
// 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)
{
// determine if the escape key was pressed
if (e.Key == VirtualKey.Escape)
{
var view = ApplicationView.GetForCurrentView ();
if (view.IsFullScreenMode)
{
// Exit full screen
view.ExitFullScreenMode ();
}
}
}
private void btnFullScreen_Click (object sender, RoutedEventArgs e)
{
ApplicationView view = ApplicationView.GetForCurrentView ();
// determine whether the current mode is full screen
if (view.IsFullScreenMode)
{
// Exit full screen mode
view.ExitFullScreenMode ();
lblMsg.Text = "Exit full screen mode";
}
else
{
// try to enter full screen mode
bool isSuccess = view.TryEnterFullScreenMode ();
if (isSuccess)
{
lblMsg.Text = "Enter full screen mode";
}
else
{
lblMsg.Text = "Failed to try to enter full screen mode";
}
}
}
private void btnShowStandardSystemOverlays_Click (object sender, RoutedEventArgs e)
{
ApplicationView view = ApplicationView.GetForCurrentView ();
// Whether to display the system UI in full screen state, such as the title bar and task bar
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. Window Size
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 = "Try changing the window size" Click = "btnChangeSize_Click" Margin = "0 10 0 0" />
</ StackPanel>
</ Grid>
</ Page>
UI/ScreenSize. xaml. cs
/ *
* Demonstrate knowledge about "window size"
*
* ApplicationView-used to manipulate windows and get window information
* GetForCurrentView ()-returns ApplicationView instance
* /
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-the size of the current window (units are valid pixels, all are valid pixels without special instructions)
// Note: The window size does not include the title bar, which is a system-level UI
lblMsg.Text = string.Format ("window size: {0} * {1}", Window.Current.Bounds.Width, Window.Current.Bounds.Height);
ApplicationView applicationView = ApplicationView.GetForCurrentView ();
// SetPreferredMinSize (Size minSize)-specify the minimum size allowed for the window
// Neither the minimum width nor the minimum height can be zero. What I tested here is a minimum width of 192 and a minimum height of 48.
applicationView.SetPreferredMinSize (new Size (200, 200));
// PreferredLaunchViewSize-the initial size when the window starts
// To make the PreferredLaunchViewSize setting effective, you need to set ApplicationView.PreferredLaunchWindowingMode to ApplicationViewWindowingMode.PreferredLaunchViewSize
ApplicationView.PreferredLaunchViewSize = new Size (800, 480);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
/ *
* ApplicationView.PreferredLaunchWindowingMode-the window's launch mode
* Auto-system automatically adjusts
* PreferredLaunchViewSize-determined by ApplicationView.PreferredLaunchViewSize
* FullScreen-Full Screen Launch
* /
}
protected override void OnNavigatedTo (NavigationEventArgs e)
{
// event triggered when the window size changes
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 (600, 600);
// TryResizeView (Size value)-try to set the window size to the specified size
bool success = applicationView.TryResizeView (size);
if (success)
{
lblMsg.Text = "Successful attempt to modify window size";
}
else
{
lblMsg.Text = "Failed to modify window size";
}
// Note: How to modify the display position of the window? have no idea for now
}
}
}
OK
[Download source code]