As part of the Windows App SDK, WinUI 3 provides a modernized UI framework for building Windows 10 and Windows 11. This 3-part blog aims to help members new to Windows development quickly build familiarity using the Window App SDK through a fun sample app. This post is only part 1 of the 3-part Windows…
As part of the Windows App SDK, WinUI 3 provides a modernized UI framework for building Windows 10 and Windows 11. This 3-part blog aims to help members new to Windows development quickly build familiarity using the Window App SDK through a fun sample app.
This post is only part 1 of the 3-part Windows App SDK blog and is scoped to showing you how to use WinUI 3 controls to create a simple working user interface. Part 2 and 3 are for windowing and single instancing.
Sample app overview
We are going to build an app with buttons that produce drum sounds (DrumPad). As simple as this demo app is, it shows some cool things you can do right away with the Windows App SDK (WinAppSDK):
Customizing windowing options so that the user can multitask with the app always on top or have a full immersive experience
Making the app single-instanced to reduce synchronization issues between instances
Prerequisites
Install tools for developing apps for Windows 10 and Windows 11 here.
Create a WinUI 3 app using the Blank App, Packaged (WinUI 3 in Desktop) template, and name it DrumPad.
Project template structure
In the WinUI 3 project template, most of our code will live in MainWindow.xaml and MainWindow.xaml.cs
MainWindow.xaml is a XAML file where we will define all of our UI elements, called “controls”, that will make up the visual layer of our application.
MainWindow.xaml.cs is the C# code-behind file where we will put all the logic that lets us interact with our application.
UI layout design
The following WinUI 3 controls are used to represent components of a drum pad:
DropDownButton: includes a chevron to indicate a menu can be opened
ToggleSwitch: a switch that can be toggled between dark/light mode
Button: has a click user interaction and will trigger a unique drum sound
Grid: made of rows and columns and is used to position the other controls
Deleting partial template code
The default project template comes with some blocks of code you’ll want to delete so we can replace them with our own markup and implementation:
MainWindow.xaml:
MainWindow.xaml.cs:
// Delete the following template code private void myButton_Click(object sender, RoutedEventArgs e) { myButton.Content = “Clicked”; }
Defining the layout
In your MainWindow.xaml we will start by defining the set of nested grids and specify their controls and positioning. Open MainWindow.xaml in the XML editor view and inside the element add this content:
NOTE: Auto and * are used to specify the height and width above to create a responsive layout. The controls held within the Grids are not fixed in size and can adjust to fill in spaces as the user resizes the app window.
Setting up remaining controls
STEP 1: Add DropDownButton & ToggleSwitch:
STEP 2: Add Buttons:
STEP 3: Specify how the Grid should position these Buttons:
STEP 4: Apply standardized styling to all the Buttons:
Result
As simple as that, we should have a working visual layer built out using WinUI 3 controls. Choose x64 as your target platform, then press F5 to run the project solution. You should see:
Satya Nadella, Chairman and CEO, shared the below communication with Microsoft employees this morning. As we begin the new year, it’s clear that we’re entering the next innings of this AI platform shift. 2025 will be about model-forward applications that reshape all application categories. More so than any previous platform shift, every layer of the……
Satya Nadella, Chairman and CEO, shared the below communication with Microsoft employees this morning. As we begin the new year, it’s clear that we’re entering the next innings of this AI platform shift. 2025 will be about model-forward applications that reshape all application categories. More so than any previous platform shift, every layer of the…
Celebrating Windows 11 PC innovations announced at CES
As we reflect on the incredible innovations showcased at CES 2025, it’s evident that the future of Windows 11 will enable new possibilities and experiences for our customers. Throughout the last year and this week at CES, our partners continue to adv Source
As we reflect on the incredible innovations showcased at CES 2025, it’s evident that the future of Windows 11 will enable new possibilities and experiences for our customers. Throughout the last year and this week at CES, our partners continue to adv