Windows App SDK Samples
repository·main·Indexed 21 days ago
https://github.com/microsoft/windowsappsdk-samplesA collection of functional samples for the Windows App SDK demonstrating features such as AI (Phi Silica, OCR, Windows ML), graphics (Mica, DWriteCore, Composition), app lifecycle, deployment, notifications, XAML Islands, and Windows Widgets. Includes guidance on building and running samples in Visual Studio, handling packaged vs. unpackaged apps, and implementing specific APIs like Dynamic Dependencies and BackgroundTaskBuilder.
What's inside windowsappsdk-samples
- The WinMLEpCatalog WinML C API allows developers to discover and manage hardware-accelerated execution providers (EPs) for machine learning inference on Windows. This sample demonstrates how to interact with these providers using the ONNX Runtime environment.
Overview of Windows Input and Composition Samples
mainThe Windows Input and Composition Samples repository provides code examples and demos for building high-performance, engaging user interfaces using the Windows App SDK.
This project focuses on the platform building blocks of the Fluent Design System, specifically leveraging the following namespaces:
Microsoft.UI.Composition: For low-level visual composition and animations.Microsoft.UI.Input: For advanced input handling and interaction.
These samples are designed for developers working with WinUI 3 who want to move beyond standard XAML controls to create custom, fluid UI experiences.
Overview of the Photo Editor Sample
mainThe Photo Editor is a sample application designed to demonstrate image viewing and editing capabilities using the Windows App SDK. It showcases how to retrieve photos from the local Pictures library and apply various photo effects.
Key technical demonstrations include:
- XAML Layout: Basic, adaptive, and tailored layouts.
- Data Binding: Using the
{x:Bind}markup extension. - UI Customization: Styling and connected animations.
- Image Effects: Utilizing Windows.UI.Composition and the Microsoft.Graphics.Win2D NuGet package for immediate-mode 2D graphics rendering.
- Performance: Loading images via data virtualization to handle large collections efficiently.
Overview of the Mica application sample
mainThe Mica application sample demonstrates how to implement the Mica material in various application types and frameworks using the Windows App SDK. Mica is a design material used for app layering and background effects in Windows applications.Overview of Windows App SDK sample categories
mainThis repository provides functional samples across several key domains of the Windows App SDK:
- Artificial Intelligence: Demonstrates Windows AI APIs (Phi Silica, OCR, Imaging) and Windows ML (running ONNX models on CPU/GPU/NPU).
- App Lifecycle & System Services: Covers activation kinds, single/multi-instancing, power/system state notifications, app restarts, and Share Target functionality.
- Deployment: Shows how to use the Deployment Manager, launch installers without console windows, and run unpackaged (non-MSIX) applications.
- Graphics & UI: Includes Mica material implementation, DWriteCore text rendering, Windowing APIs, and Microsoft.UI.Composition/Input/SceneGraph.
- Notifications: Showcases both Push and App Notifications.
- Islands: Demonstrates adding WinAppSDK XAML content into existing Win32 applications.
- Widgets: Demonstrates authoring Windows Widgets.
- Runtime Components: Shows how to author Windows Runtime Components in C# with custom WinUI controls.
Use the AppWindow class for window management
mainThe Windowing gallery samples demonstrate how to use the
AppWindowclass to manage an application's window. This includes managing window size, position, and title bar customization.Title Bar Customization Note
Customizing a window's TitleBar using the
AppWindowTitleBarAPIs is only supported on Windows 11 or later. To ensure compatibility, you should check support using theIsCustomizationSupportedmethod.// Conceptual check for TitleBar customization support if (appWindowTitleBar.IsCustomizationSupported()) { // Perform customization }Author and consume C# Windows Runtime Components with WinUI controls
mainThis sample demonstrates the workflow for creating C# components that contain WinUI controls (such as
UserControlandCustom Control) using C#/WinRT, and subsequently consuming those components in both C++ and C# applications.Project Structure
- WinUICsComponent: The core C# Windows Runtime component library. It uses the
Microsoft.Windows.CsWinRTNuGet package to generate the component. - CppApp: A packaged C++ WinUI application that consumes the component.
- CppAppUnpackaged: An unpackaged C++ WinUI application that consumes the component.
- CsApp: A packaged C# WinUI application that consumes the component.
- WinUICsComponent: The core C# Windows Runtime component library. It uses the
Use Push Notifications in an unpackaged app
mainThis sample demonstrates how to use the Windows App SDK Push Notifications APIs within an unpackaged application. It covers two primary workflows:
- Requesting a WNS Channel URI: The app uses the Windows App SDK to obtain a unique WNS Channel URI. This URI identifies the specific app instance for a current user on a specific device, which an external app server uses to target notifications to that app.
- Handling Activations: The app registers for both foreground and background activation to ensure it can respond to incoming notifications regardless of its current state.
Load resources using MRT Core
mainMRT Core is the modern resource loading library used in WinUI 3 and the Windows App SDK. It providesResourceLoaderandResourceManagerto load resources from multiple resource files and allows for selecting specific versions of named resources based on the application's context.Use Microsoft.UI.Input APIs in C# WinUI samples
mainThese samples provide implementations for the
Microsoft.UI.Inputnamespace, demonstrating how to handle user input in Windows applications. They specifically showcase:- Usage of various
Microsoft.UI.InputAPIs. - Handling of Keyboard events.
- Implementation of Keyboard accelerators using WinUI.
- Usage of various
Available Windows ML Sample Categories
mainThe repository provides samples across multiple languages and deployment types:
C++ Samples
- CppConsoleDesktop: Basic console app demonstrating EP discovery, command-line options, and model compilation.
- CppConsoleDesktop.FrameworkDependent: Uses shared runtime for a smaller deployment footprint.
- CppConsoleDesktop.SelfContained: Standalone deployment with no runtime dependencies.
- WinMLEpCatalog (CMake): Uses the WinML C API with CMake build system and automatic NuGet restore.
- cpp-abi: Direct implementation using raw COM interfaces and automatic ABI header generation.
C# Samples
- CSharpConsoleDesktop: Basic console application using shared helpers.
- GUI Applications: Image classification examples implemented in WPF, Windows Forms, and WinUI 3.
Python Samples
- SqueezeNetPython: Demonstrates image classification using WinML Python bindings and batch image processing.
What is a WinAppSDK ContentIsland?
mainA WinAppSDK ContentIsland is a set of APIs designed to connect two different UI frameworks within a single application. This allows developers to host modern Xaml-based content (like WinUI) inside legacy or alternative frameworks, such as Win32 or WinForms.