Connect with us

Microsoft

Build your first WinUI 3 app (Part 1)

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…

Published

on

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): 

  • Working with simple and easy-to-use UI controls from Windows UI Library (WinUI) 3
  • 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

  1. Install tools for developing apps for Windows 10 and Windows 11 here.
  2. 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:

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Business

Introducing CoreAI – Platform and Tools

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……

Published

on

By

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…

Source

Continue Reading

Microsoft

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

Published

on

By

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

Continue Reading

Business

The future of retail with Dynamics 365 AI-powered ERP solutions

This year at NRF, we will showcase the latest AI and agent innovations in Dynamics 365 AI-powered ERP and Service solution. Learn more. Source

Published

on

By

This year at NRF, we will showcase the latest AI and agent innovations in Dynamics 365 AI-powered ERP and Service solution. Learn more.

Source

Continue Reading

Trending

Copyright © 2021 Today's Digital.