FluentWPF Documentation

repository·master·Indexed 23 days ago

https://github.com/sourcechord/fluentwpf

A library that implements the Windows Fluent Design System for WPF applications. It provides visual effects including Acrylic (via AcrylicWindow and AcrylicBrush), Reveal effects for standard controls, and ParallaxView for scrolling effects. The library also includes access to system accent colors and dynamic resources for Base, Alt, and Chrome color palettes that adapt to Light and Dark modes.

Tokens
2.1K
Snippets
6
Records
11
Agent score
32%

What's inside FluentWPF

  1. Overview of FluentWPF features

    master

    FluentWPF brings the Windows Fluent Design System to WPF applications. Key features include:

    • Acrylic: Provides AcrylicWindow and AcrylicBrush for translucent, material-like effects.
    • Reveal: Provides Reveal-style visual effects for standard controls like Button, TextBox, and ListBox.
    • ParallaxView: Implements parallax scrolling effects.
    • AccentColors: Provides access to system accent colors.
  2. Use AcrylicWindow for semi-transparent windows

    master

    The AcrylicWindow class allows you to create windows with the Windows Acrylic effect. You can use it as a base class for your window or as an attached property on a standard Window.

    As a Base Class

    When using AcrylicWindow as your window's base class, you must remove the standard Window base class definition from your code-behind.

    As an Attached Property

    You can enable the acrylic effect on a standard Window by setting the fw:AcrylicWindow.Enabled attached property to True in XAML.

    <!-- As a Base Class -->
    <fw:AcrylicWindow x:Class="WpfApp1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:fw="clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF"
            Title="MainWindow" Height="300" Width="300">
        <Grid Background="#70FFFFFF">
            <TextBlock Text="This is AcrylicWindow" />
        </Grid>
    </fw:AcrylicWindow>
    
    <!-- As an Attached Property -->
    <Window x:Class="WpfApp1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:fw="clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF"
            fw:AcrylicWindow.Enabled="True">
        <Grid>
        </Grid>
    </Window>
  3. Prepare FluentWPF for use in XAML

    master

    After installing the NuGet package, you must perform two setup steps to use the library's features:

    1. Add the XAML namespace: Register the fw prefix in your Window or UserControl XAML to access FluentWPF types.
    2. Merge ResourceDictionaries: Add the FluentWPF control styles to your App.xaml so that the styles are available globally throughout your application.
    <!-- 1. Add XAML namespace -->
    xmlns:fw="clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF"
    
    <!-- 2. Add ResourceDictionary to App.xaml -->
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                 <!--  FluentWPF Controls  -->
                <ResourceDictionary Source="pack://application:,,,/FluentWPF;component/Styles/Controls.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
  4. Enable the Reveal effect for controls

    master
    The Reveal effect adds a light-following visual effect to controls. To enable it, you must set fw:PointerTracker.Enabled="True" on a parent container (like a Grid or StackPanel) that contains the controls you want to have the effect.
  5. Use ParallaxView for parallax scrolling effects

    master

    The ParallaxView control creates a parallax effect between a background image and a foreground content source (like a ListBox).

    Set VerticalShift and HorizontalShift to control the intensity of the effect, and bind the Source property to the element being scrolled.

    <Grid>
        <fw:ParallaxView VerticalShift="200" HorizontalShift="200"
                         Source="{Binding ElementName=list}">
            <Image Source="/Assets/Images/1.jpg" Stretch="UniformToFill"/>
        </fw:ParallaxView>
        <ListBox x:Name="list" ItemsSource="{Binding Items}"/>
    </Grid>
  6. Use AcrylicBrush for UI elements

    master

    The AcrylicBrush can be used to apply the acrylic effect to specific UI elements (like a Rectangle or Border) by referencing a source element that provides the background context.

    <!-- Apply AcrylicBrush to a Rectangle, using 'grid' as the source -->
    <Rectangle Grid.ColumnSpan="2"
               Margin="40"
               Fill="{fw:AcrylicBrush grid}"
               Stroke="Black" />
  7. Reference Reveal effect styles

    master

    Use the following styles to apply the Reveal effect to standard WPF controls:

    ControlStyle Name
    ButtonButtonRevealStyle
    ButtonButtonAccentRevealStyle
    ButtonButtonRoundRevealStyle
    ButtonButtonRoundAccentRevealStyle
    TextBoxTextBoxRevealStyle
    PasswordBoxPasswordBoxRevealStyle
    ListBoxListBoxRevealStyle
    ComboBoxComboBoxRevealStyle
  8. Use System Base, Alt, and Chrome colors

    master

    FluentWPF provides a set of dynamic resources for standard Windows color palettes (Base, Alt, Chrome, and Opacity colors) that automatically adapt to Light and Dark modes.

    Base Colors

    Used for primary backgrounds. Examples: SystemBaseHighColorBrush, SystemBaseMediumColorBrush.

    Alt Colors

    Used for alternative UI elements. Examples: SystemAltHighColorBrush, SystemAltMediumColorBrush.

    Chrome Colors

    Used for window chrome and borders. Examples: SystemChromeHighColorBrush, SystemChromeLowColorBrush.

    Usage

    Access these using DynamicResource to ensure they update when the system theme changes.

    <!-- Example usage of Base and Alt colors -->
    <Border Background="{DynamicResource SystemBaseHighColorBrush}"/>
    <TextBlock Foreground="{DynamicResource SystemAltHighColorBrush}"/>
  9. Access System Accent Colors

    master

    FluentWPF provides access to the user's system accent colors via the fw:AccentColors class. These can be accessed using StaticResource or Binding.

    Available brushes include:

    • ImmersiveSystemAccentBrush (The main accent color)
    • ImmersiveSystemAccentLight1Brush through ImmersiveSystemAccentLight3Brush (Lighter variants)
    • ImmersiveSystemAccentDark1Brush through ImmersiveSystemAccentDark3Brush (Darker variants)
  10. Configure AcrylicWindow properties

    master

    The AcrylicWindow provides several properties to customize the appearance of the acrylic material:

    Property NameTypeDescription
    TintColorColorThe color tint for the semi-transparent acrylic material.
    TintOpacitydoubleThe degree of opacity of the color tint.
    NoiseOpacitydoubleThe degree of opacity of the noise layer.
    FallbackColorColorThe color used when the window is inactive.
    AcrylicWindowStyleenumThe style of the window. Options: Normal, NoIcon, None.