WPF UI Documentation

repository·main·Indexed 27 days ago

https://github.com/lepoco/wpfui

An open-source library that implements the Microsoft Fluent Design System for WPF applications, providing 77+ custom controls, themed visual styles (Light, Dark, High Contrast), and Win32 interop for Windows 11 effects like Mica and Acrylic. The ecosystem includes the core Wpf.Ui library and specialized packages for Dependency Injection, Syntax Highlighting, System Tray integration, and FlaUI automated testing. It supports .NET 10/9/8 and .NET Framework 4.6.2/4.7.2/4.8.1.

Tokens
32.8K
Snippets
73
Records
168
Agent score
93%

What's inside WPF UI

  1. Overview of Wpf.Ui.Abstractions

    main
    The Wpf.Ui.Abstractions library provides common interfaces and contracts used throughout the Wpf.Ui ecosystem. Its primary purpose is to decouple core library features and provide extension points for developers to implement custom navigation and control behaviors.
  2. Overview of WPF UI

    main

    WPF UI is a library that provides a Fluent design experience for the WPF framework. It includes:

    • Modified Base Elements: Overrides standard elements like Page, ToggleButton, or List to match Fluent design.
    • Additional Controls: Provides new immersive controls such as Navigation, NumberBox, Dialog, and Snackbar.
    • Themes and Navigation: Built-in support for Fluent themes and modern navigation patterns.
  3. Overview of WPF UI

    main

    WPF UI is an open-source library that implements the Microsoft Fluent Design System for Windows Presentation Foundation (WPF) applications. It allows developers to modernize legacy WPF applications with contemporary Windows 11 visual styles (including Mica, Acrylic, and Tabbed backdrops) without migrating to WinUI 3 or MAUI.

    Key Features:

    • 77+ custom controls.
    • Full theming system (Light, Dark, and High Contrast modes).
    • Win32 interop for modern window chrome effects.
    • Navigation services.
    • Support for Fluent System Icons.
    • Support for multiple frameworks: .NET 10/9/8 and .NET Framework 4.6.2/4.7.2/4.8.1.
  4. Overview of WPF UI testing strategy

    main

    WPF UI uses a two-tier testing strategy:

    1. Unit Tests: Focus on pure logic, extension methods, and animation providers. They use XUnit 2.9.3 and NSubstitute 5.3.0 for mocking.
    2. Integration Tests: Focus on end-to-end UI automation (window management, navigation, dialogs, title bar). They use XUnit v3 3.2.0, FlaUI.UIA3 5.0.0, and AwesomeAssertions 9.3.0.
  5. Understand the Theming and Appearance System

    main

    Theming is managed by five core components that coordinate to update the UI:

    • ApplicationThemeManager: Handles high-level theme selection (e.g., Light vs Dark).
    • ApplicationAccentColorManager: Manages accent colors used throughout the UI.
    • SystemThemeWatcher: Monitors OS-level theme changes to keep the app in sync.
    • WindowBackgroundManager: Manages the appearance of window backgrounds.
    • ResourceDictionaryManager: Performs the actual swapping of XAML ResourceDictionary objects.

    Theme Change Flow: User $\rightarrow$ OS Settings $\rightarrow$ WndProc $\rightarrow$ SystemThemeWatcher $\rightarrow$ ApplicationThemeManager $\rightarrow$ ResourceDictionaryManager $\rightarrow$ Application.Resources $\rightarrow$ UI Update.

  6. WPF UI Architectural Patterns

    main

    When building with WPF UI, be aware of the following architectural patterns used in the library:

    • Control Architecture: Controls follow a folder-per-control pattern (paired .cs and .xaml files) and implement capability interfaces like IAppearanceControl or IIconControl.
    • Theming System: Managed via the ApplicationThemeManager, which handles runtime resource dictionary swapping. Accent colors are derived from system settings via WinRT UISettings or DWM registry.
    • Win32 Interop: Uses a three-layer architecture consisting of CsWin32 source-generated P/Invoke, managed wrappers (UnsafeNativeMethods), and high-level utilities to enable DWM backdrop effects and custom window chrome.
  7. Understand the Win32 Interop Architecture

    main

    WPF UI uses a three-layer architecture to provide Fluent Design features (like Mica, Acrylic, and custom title bars) that are not natively available in WPF. This architecture isolates raw Win32 platform calls from the high-level WPF controls.

    Architecture Layers:

    1. Layer 1: CsWin32 Source Generation: Uses Microsoft's CsWin32 to generate type-safe P/Invoke bindings in the Windows.Win32 namespace based on declarations in NativeMethods.txt.
    2. Layer 2: Managed Wrappers (src/Wpf.Ui/Interop/): Provides exception-safe, handle-validated access to native APIs. This layer includes UnsafeNativeMethods.cs for handle validation, UnsafeReflection.cs for enum/struct casting, and PInvoke.cs for custom platform-specific declarations (like SetWindowLongPtr).
    3. Layer 3: Utilities (src/Wpf.Ui/Win32/): High-level utilities for OS version detection (e.g., IsOSWindows11OrNewer) and feature gating to ensure graceful degradation on older Windows versions.
  8. Project Identity and Core Specifications

    main

    WPF UI (wpfui) is an open-source WPF control library that implements the Microsoft Fluent Design System. It is designed to work across multiple .NET versions and provides a suite of controls, appearance managers, and Win32 interop wrappers.

    Key Technical Details:

    • NuGet Package ID: WPF-UI
    • XAML Namespace: http://schemas.lepo.co/wpfui/2022/xaml (use prefix ui)
    • Supported Platforms: .NET 10/9/8 (Windows TFMs) and .NET Framework 4.6.2/4.7.2/4.8.1
    • License: MIT