Universal Windows Platform (UWP) Introduction
What is UWP?
The Universal Windows Platform (UWP) provides a common app platform for all Windows devices, enabling developers to create a single package that adapts to PCs, tablets, phones, Xbox, HoloLens, and IoT devices.
Key Features
- Responsive design with adaptive UI
- Rich API surface for native Windows capabilities
- Secure sandboxed execution
- Microsoft Store distribution
- Cross-device continuity and notifications
Getting Started
Follow these steps to create your first UWP app.
- Install Visual Studio 2022 with the “Universal Windows Platform development” workload.
- Launch Visual Studio and select Create a new project → Blank App (Universal Windows).
- Choose a project name and target version (e.g., Windows 10, version 1903).
- Press
F5to build and run the default app on your local machine.
For a quick hands‑on tutorial, see the sample code section.
Sample Code
This minimal UWP app displays a button that toggles background color.
<Window
x:Class="SampleApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Sample App">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Toggle Color"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Click="OnToggleClick"/>
</Grid>
</Window>
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace SampleApp
{
public sealed partial class MainWindow : Window
{
private bool _isDark = false;
public MainWindow()
{
this.InitializeComponent();
}
private void OnToggleClick(object sender, RoutedEventArgs e)
{
_isDark = !_isDark;
this.RequestedTheme = _isDark ? ElementTheme.Dark : ElementTheme.Light;
}
}
}