Getting Started with WinUI

Welcome to WinUI, the modern UI platform for Windows. This guide will walk you through the initial steps to start building beautiful and performant Windows applications with WinUI 3.

Tip: WinUI 3 is the latest native UI platform for Windows, offering a rich set of controls and modern APIs for building Windows applications. It's the evolution of the Universal Windows Platform (UWP) and the Fluent Design System.

Prerequisites

Before you begin, ensure you have the following installed:

You can install Visual Studio and the necessary SDKs from the Visual Studio website.

Step 1: Install the WinUI 3 Project Templates

Open Visual Studio Installer. Select "Modify" for your Visual Studio installation. Under "Individual components", search for "WinUI" and ensure "Windows App SDK C# templates" is checked. If you don't see it, you may need to install the latest Visual Studio preview or check for updates.

Note: The WinUI 3 project templates are bundled with the Windows App SDK. Make sure you have the latest version of the Windows App SDK installed via NuGet or through the Visual Studio Installer.

Step 2: Create Your First WinUI 3 Application

Now that you have the templates installed, let's create a new project:

  1. In Visual Studio, go to File > New > Project...
  2. Search for "WinUI" and select the Blank App, Packaged (WinUI 3 in Desktop) template.
  3. Click Next.
  4. Give your project a name (e.g., "MyFirstWinUIApp") and choose a location.
  5. Click Create.
Visual Studio new project dialog for WinUI
Visual Studio new project dialog selecting WinUI template.

Step 3: Run Your Application

After the project is created, you should see a basic WinUI application structure. To run it:

  1. Ensure the target is set to Windows PC in the Visual Studio toolbar.
  2. Click the Start Debugging button (or press F5).

A simple window will appear, showcasing the default WinUI application frame. This is your starting point!

Step 4: Understanding the Project Structure

Your new WinUI project will have a few key files:

Let's look at a simplified example of MainWindow.xaml:

<Window x:Class="MyFirstWinUIApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:MyFirstWinUIApp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock Text="Hello, WinUI!" FontSize="32"/> </StackPanel> </Window>

And the corresponding MainWindow.xaml.cs:

using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; namespace MyFirstWinUIApp { public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } } }

Next Steps

Congratulations! You've successfully set up your development environment and created your first WinUI application. Now you can explore:

Continue to the Tutorials section to build more complex features.

Important: WinUI 3 is continuously updated. Always ensure you are using the latest stable versions of Visual Studio and the Windows App SDK for the best experience and latest features.