advertisement
9. Adaptive UI
Windows 10 Apps Development
A Universal Windows Platform (UWP) application can run on many different devices and each device has its own form of input, screen resolutions, DPI density, and other unique characteristics.
In Windows 10, with the help of new universal controls, layout panels, and tooling you can adapt your UI easily to the devices your application may run on. For example, when your
UWP application is running either on a desktop computer, a mobile device or on a tablet, you can tailor the UI to take advantage of different screen resolution, screen sizes and DPI density.
In Windows 10, you can easily target your UI to multiple devices with the following features:
You can enhance your UI for different screen resolutions and screen sizes by using universal controls and layout panels.
Common input handling allows you to receive input through a touch pad, a pen, a mouse, a keyboard, or a controller such as a Microsoft Xbox controller.
With the help of Tools, you can design your application UI that can adapt to different screen resolutions.
Adaptive scaling adjusts to the resolution and DPI differences across devices.
In Windows 10, you can easily arrange, resize and position applications in any way you want. It also gives some sort of flexibility to the user to use your application the way they want. In Windows 10, there are various ways to implement responsive techniques in your
UWP application, so it looks great no matter what is the screen or window size.
VisualStateManager
In Windows 10, the VisualStateManager class has two new mechanisms with the help of which you can implement a responsive design in your UWP applications. The new
VisualState.StateTriggers allows the developer to check certain conditions like the window height or window width and then the VisualState.Setters APIs define visual states in response to those certain conditions.
Let us have a look at the example given below in which some controls are added in stack panel.
<Page
x:Class="UWPAdaptiveUI.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPAdaptiveUI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
50
Windows 10 Apps Development
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<!-- VisualState to be triggered when window
width is >=720 effective pixels. -->
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="myPanel.Orientation"
Value="Horizontal" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel x:Name="myPanel" Orientation="Vertical">
<TextBlock Text="Windows 10 Tutorials: Text block 1. "
Style="{ThemeResource BodyTextBlockStyle}"/>
<TextBlock Text="Windows 10 Tutorials: Text block 2. "
Style="{ThemeResource BodyTextBlockStyle}"/>
<TextBlock Text="Windows 10 Tutorials: Text block 3. "
Style="{ThemeResource BodyTextBlockStyle}"/>
</StackPanel>
</Grid>
</Page>
Now VisualStateManager, will adjust the orientation of stack panel based on the window’s width. If width is >= 720, then the orientation will become Horizontal otherwise it will remain vertical. When the above code is compiled and executed, you will see the following window, which contains three text blocks in vertical order.
51
advertisement
Related manuals
advertisement
Table of contents
- 5 Introduction
- 5 Universal Windows app
- 6 Characteristics of UWP apps
- 6 Development Choices
- 7 Windows 10 – UWP
- 7 Universal Windows Platform (UWP)
- 8 Devices Supported by Windows
- 8 Advantages of UWP
- 8 Setup for UWP Development
- 10 Windows 10 – First App
- 19 Windows 10 – Store
- 20 Monetization
- 20 Microsoft Advertising
- 27 Windows 10 – XAML Controls
- 27 XAML Emerging Story
- 28 Layout Controls
- 29 UI Controls
- 35 XAML – Data Binding
- 35 One-way Data Binding
- 37 Two-way Data Binding
- 40 Element Binding
- 43 XAML Performance
- 43 Progressive Rendering
- 47 Deferred Loading
- 51 Adaptive Design
- 51 New Built-in Features
- 52 Universal Building Blocks
- 54 Adaptive UI
- 54 VisualStateManager
- 56 RelativePanel
- 59 Adaptive Code
- 59 Writing Code
- 61 Win32 APIs in the UWP
- 70 File Management
- 70 File Locations
- 71 File Handling APIs
- 77 SQLite Database
- 77 What is SQLite?
- 77 Advantages of SQLite
- 89 App to App Communication
- 89 Getting Your App Ready
- 96 App Localization
- 96 Translating UI Resources
- 112 App Lifecycle
- 113 Process State Transition
- 120 Background Execution
- 120 Create and Register Background Task
- 127 APP Services
- 136 Web Platform
- 136 Advantages
- 143 Connected Experience
- 144 Roaming in Windows
- 151 Navigation
- 151 Page Models
- 151 Navigation Structure
- 158 Networking
- 158 Capabilities
- 159 Networking Technologies
- 162 HttpClient
- 164 Cloud Services
- 164 Microsoft Account
- 175 Live Tiles
- 175 Tile Anatomy
- 175 Updating Tiles
- 180 Sharing Contract
- 180 Sharing Content
- 181 Receiving Shared Content
- 188 Porting to Windows
- 188 Porting a Windows 8.x Project to a UWP Project