应用笔记 · 2025年10月24日

FluentAvalonia Icon and Color system

Icon System Overview

FluentAvalonia provides a flexible icon system with multiple display methods and reusable resources. The system consists of two main parts:

  1. Icon Elements – UI controls that display icons directly
  2. Icon Sources – Reusable resources that define icon appearances

FluentAvalonia Icon System Architecture

Sources: samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml26-176 samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml179-284

Icon Elements

FluentAvalonia provides specialized icon elements that inherit from the base FAIconElement class:

Icon Element Purpose Key Properties
ui:SymbolIcon Fluent Icons collection SymbolFontSize
ui:FontIcon Font glyphs GlyphFontFamilyFontSize
ui:FAPathIcon Vector paths DataWidthHeight
ui:BitmapIcon Bitmap images UriSourceShowAsMonochrome
ui:ImageIcon Various image sources SourceWidthHeight

SymbolIcon

The ui:SymbolIcon control displays icons from Microsoft’s Fluent Icons collection embedded in the FluentAvalonia assembly.

The Symbol property accepts values from the Symbol enum, which contains predefined icons matching WinUI.

FontIcon

The ui:FontIcon control displays font glyphs as icons, commonly used with SymbolThemeFontFamily.

FAPathIcon

The ui:FAPathIcon control displays vector paths as icons.

BitmapIcon

The ui:BitmapIcon control displays bitmap images with optional monochrome conversion.

ImageIcon

The ui:ImageIcon control displays various image types including DrawingImage.

Sources: samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml28-176

Icon Sources

Icon sources provide reusable icon definitions that can be referenced throughout your application. They mirror the available icon elements:

Icon Source Purpose Key Properties
ui:SymbolIconSource Fluent Icons collection SymbolFontSize
ui:FontIconSource Font glyphs GlyphFontFamilyFontSize
ui:PathIconSource Vector paths Data
ui:BitmapIconSource Bitmap images UriSourceShowAsMonochrome
ui:ImageIconSource Various image sources Source

Icon sources are typically defined in resource dictionaries:

Icon Source Usage Patterns

Icon sources can be used in two ways:

  1. Direct IconSource Property: Controls like ui:InfoBar accept IconSource directly
  2. IconSourceElement: Use ui:IconSourceElement to display icon sources anywhere

Sources: samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml13-17 samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml182-281

Symbol Enumeration

FluentAvalonia provides predefined icons through the Symbol enum, corresponding to the WinUI Fluent Icon collection with both filled and regular variants.

Symbol System Architecture

Symbol Usage

The symbols can be used in multiple ways:

  1. SymbolIcon with Symbol enum:

  1. SymbolIconSource in resources:

  1. FontIcon with SymbolThemeFontFamily:

Symbol Browser Implementation

The FAControlsGallery includes a searchable symbol browser that displays all available symbols with their names, glyphs, and Unicode points:

Sources: samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml286-347 samples/FAControlsGallery/Pages/DesignPages/DesignIconsPage.axaml39-43 samples/FAControlsGallery/Styling/ControlExampleStyles.axaml48-49

Color System

FluentAvalonia provides a comprehensive color system following the WinUI color palette, organized into categories and available as XAML resources.

Color System Architecture

Color Categories

FluentAvalonia organizes colors into functional categories:

Category Purpose Common Brushes
Text Colors Text elements with emphasis levels TextFillColorPrimaryBrushTextFillColorSecondaryBrushTextFillColorTertiaryBrush
Fill Colors Interactive control fills ControlFillColorDefaultBrushControlFillColorSecondaryBrushControlFillColorTertiaryBrush
Stroke Colors Borders and outlines ControlStrokeColorDefaultBrushControlStrokeColorSecondaryBrushCardStrokeColorDefaultBrush
Background Colors Various background types CardBackgroundFillColorDefaultBrushSolidBackgroundFillColorBaseBrushLayerFillColorDefaultBrush
Signal Colors Status indicators SystemFillColorCriticalBrushSystemFillColorSuccessBrush

Sources: samples/FAControlsGallery/Pages/DesignPages/ColorsPage.axaml87-123 samples/FAControlsGallery/Pages/DesignPages/BackgroundColorsPage.axaml1-308

Color Categories

FluentAvalonia organizes colors into several main categories, each with specific use cases:

Text Colors

Used for text elements with different emphasis levels (primary, secondary, tertiary).

Fill Colors

Used for filling UI controls and elements like buttons, toggles, and other interactive components.

Stroke Colors

Used for borders and outlines of UI elements.

Background Colors

Used for different types of backgrounds in the application:

  1. Solid Background: Base backgrounds for the application
  2. Card Background: For card-like UI elements
  3. Layer: For layered UI components
  4. Mica Background: Matches Windows 11 Mica material (simulated in Avalonia)
  5. Acrylic Background: Matches Windows acrylic material (simulated in Avalonia)
  6. Accent Acrylic Background: Accent-colored acrylic backgrounds

Signal Colors

Used for status indicators, warnings, and other informational elements.

Sources: samples/FAControlsGallery/Pages/DesignPages/BackgroundColorsPage.axaml10-305

Using Colors in XAML

Colors in FluentAvalonia are accessed through DynamicResource markup extensions. Each color is available both as a raw color value and as a brush.

Color Naming Convention

Resource Type Naming Pattern Example
Color [Category][Purpose][Variant] CardStrokeColorDefault
Brush [Category][Purpose][Variant]Brush CardStrokeColorDefaultBrush

Color Variants

Variant Purpose Usage
Default Standard variant Rest state
Secondary Less prominent Hover state
Tertiary Least prominent Pressed state
Disabled Disabled state Disabled controls
Selected Selected state Selected items

State-Based Color Usage

Sources: samples/FAControlsGallery/Pages/DesignPages/ColorsPage.axaml89-104 samples/FAControlsGallery/Pages/DesignPages/ColorsPage.axaml11-75

Background Color Categories

FluentAvalonia provides specialized background colors for different UI elements and layering scenarios.

Card Background Colors

Used to create “cards” – content blocks that live on pages and layer backgrounds:

Card Background Brush Description Usage
CardBackgroundFillColorDefaultBrush Standard card background Default card color
CardBackgroundFillColorSecondaryBrush Slightly darker alternative Alternate card color
CardBackgroundTertiaryBrush Hover and pressed states Interactive card states

Solid Background Colors

Used for the base layers of an application:

Solid Background Brush Description Usage
SolidBackgroundFillColorBaseBrush Base background Bottom-most layer
SolidBackgroundFillColorBaseAltBrush Alternative base background Alternative bottom layer
SolidBackgroundFillColorSecondaryBrush Secondary background Darker background option
SolidBackgroundFillColorTertiaryBrush Tertiary background Content layer color
SolidBackgroundFillColorQuarternaryBrush Quaternary background Alt content layer color

Layer Colors

Used for layering content on top of backgrounds:

Layer Brush Description Usage
LayerFillColorDefaultBrush Standard layer Content layer color
LayerFillColorAltBrush Alternative layer Alternate content layer
LayerOnAcrylicFillColorDefaultBrush Layer on acrylic surfaces Acrylic content layer
LayerOnMicaBaseAltFillColorDefaultBrush Layer on Mica base Active tab rest, content layer
LayerOnMicaBaseAltFillColorTertiaryBrush Layer on Mica base tertiary Active tab drag
LayerOnMicaBaseAltFillColorTransparentBrush Layer on Mica base transparent Inactive tab rest
LayerOnMicaBaseAltFillColorSecondaryBrush Layer on Mica base secondary Inactive tab hover

Specialized Background Colors

Mica Background Colors

  • MicaBackgroundFillColorBaseBrush: Bottom-most layer of Mica experience
  • MicaBackgroundFillColorBaseAltBrush: Default tab band background

Acrylic Background Colors

  • AcrylicBackgroundFillColorBaseBrush: Bottom-most layer of acrylic surface (uses fallback color)
  • AcrylicBackgroundFillColorDefaultBrush: Default acrylic recipe for flyouts (uses fallback color)

Accent Acrylic Background Colors

  • AccentAcrylicBackgroundFillColorBaseBrush: Bottom-most layer of accent acrylic surface
  • AccentAcrylicBackgroundFillColorDefaultBrush: Default accent acrylic recipe

Sources: samples/FAControlsGallery/Pages/DesignPages/BackgroundColorsPage.axaml10-305

Best Practices

Icons

  1. Consistency: Use the same icon style throughout your application
  2. Standard Sizes: Keep icons at standard sizes (16px, 18px, 20px, 24px, 28px, 32px)
  3. Color Inheritance: Icons inherit foreground color by default, adapting to themes
  4. Icon Sources: Use icon sources in resource dictionaries for reusable icons
  5. Accessibility: Ensure icons have proper AutomationProperties.Name for screen readers
  6. Symbol Font: Use SymbolThemeFontFamily for consistent icon appearance

Colors

  1. Dynamic Resources: Always use DynamicResource instead of StaticResource for colors to support theme changes
  2. Purpose-Based Usage: Use colors according to their intended purpose (text colors for text, fill colors for controls)
  3. Hierarchy Respect: Use primary, secondary, and tertiary variants appropriately for visual hierarchy
  4. BackgroundSizing: Use BackgroundSizing="InnerBorderEdge" on borders with backgrounds for proper rendering
  5. High Contrast Support: The color system automatically adapts to high contrast themes
  6. Proper Naming: Follow the established naming convention for color resources

Sources: samples/FAControlsGallery/Styling/ControlExampleStyles.axaml47-49 samples/FAControlsGallery/Pages/DesignPages/BackgroundColorsPage.axaml13-21 samples/FAControlsGallery/Pages/DesignPages/DesignIconsPage.axaml19-60

Exploring Available Resources

The FAControlsGallery sample application provides comprehensive pages to explore:

  1. Available icons under the “Icons” page in the Controls section
  2. Available colors under the “Colors” page in the Design section

These pages allow you to see all available options and get the appropriate resource names for use in your application.

Sources: samples/FAControlsGallery/Pages/FAControlsPages/IconsPage.axaml1-350 samples/FAControlsGallery/Pages/DesignPages/ColorsPage.axaml1-126 samples/FAControlsGallery/Pages/DesignPages/BackgroundColorsPage.axaml1-308