Microsoft Learn

WinUI 3 Concepts

Welcome to the core concepts of WinUI 3, the latest evolution of the Windows UI Library. WinUI 3 is designed to help you build modern, beautiful, and performant applications for Windows.

What is WinUI 3?

WinUI 3 is a native UI platform for building Windows applications. It's the recommended way to create modern Windows experiences with C++, C#, or other .NET languages. WinUI 3 offers a comprehensive set of UI controls, features, and tools to empower developers.

Key Principles

Architecture Overview

WinUI 3 is built on top of the Windows App SDK. This foundation provides a unified set of APIs for building Windows applications, regardless of the project type (packaged or unpackaged).

The core components of WinUI 3 include:

XAML for UI Definition

XAML (eXtensible Application Markup Language) is used to define the visual structure of your application. It allows you to declare UI elements, their properties, and their arrangement in a clear and readable format.

<!-- Example of a simple button in XAML -->
<Button Content="Click Me" HorizontalAlignment="Center" VerticalAlignment="Center" />

Controls and Layouts

WinUI 3 provides a rich set of built-in controls for common UI patterns, such as buttons, text boxes, lists, and more. You can arrange these controls using various layout panels to create responsive and adaptive user interfaces.

Common layout panels include:

Tip: Understanding layout panels is crucial for creating UIs that adapt well to different screen sizes and resolutions.

Styling and Templating

WinUI 3 embraces powerful styling and templating capabilities. You can use styles to define consistent visual attributes for controls, and templates to completely redefine their appearance and behavior.

This allows for deep customization and the creation of unique visual themes for your applications.

Data Binding

Data binding is a fundamental concept that connects your UI elements to your application's data. This enables dynamic updates: when the data changes, the UI reflects those changes automatically, and vice versa.

WinUI 3 supports powerful data binding expressions and patterns for efficient data management.

Event Handling

User interactions are handled through events. WinUI 3 provides a comprehensive event model that allows your application to respond to user actions like button clicks, text input, and pointer movements.

// Example of handling a button click in C#
void MyButton_Click(object sender, RoutedEventArgs e)
{
    // Code to execute when the button is clicked
    System.Diagnostics.Debug.WriteLine("Button was clicked!");
}

Next Steps

Now that you have a foundational understanding of WinUI 3 concepts, explore the following sections to dive deeper: