Adonis UI Documentation

repository·master·Indexed 23 days ago

https://github.com/benruehl/adonis-ui

A lightweight UI toolkit for WPF applications providing classic but enhanced Windows visuals. It features default styles for most WPF controls, support for light and dark color schemes with runtime switching, and a custom themed title bar via AdonisWindow. The toolkit includes a Space markup extension for consistent layout dimensions and a resource-based system for overriding colors, brushes, dimensions, and styles. Requires .NET Framework 4.5 or .NET Core 3.0 or higher.

Tokens
17.9K
Snippets
42
Records
71
Agent score
82%

What's inside Adonis UI

  1. Overview of Adonis UI

    master

    Adonis UI is a lightweight, open-source UI toolkit for WPF (Windows Presentation Foundation) applications. It provides styles and templates for all major WPF controls, aiming to provide a consistent, modern visual overhaul while staying close to the original WPF look and feel.

    Key characteristics include:

    • Drop-in replacement: It favors extending WPF's built-in controls rather than creating new ones, making it easy to integrate into existing applications.
    • Zero-config by default: It requires no initial configuration to work, though it provides extensive options for controlling global and individual control behavior.
    • Enhanced visuals: Includes features like runtime color scheme switching, accent color support, custom window title bars, cursor spotlight hover effects, ripple effects, and layers.
  2. Understand Adonis UI Colors and Brushes

    master

    Adonis UI uses a layering system where colors and brushes are tightly coupled. For each layer (except the base layer), there are nine specific color definitions and corresponding brushes.

    Changing a base color (e.g., BackgroundColor) will automatically propagate to all controls using that color, such as buttons, text boxes, and radio buttons.

    Key color roles include:

    • Background: Background color of a control on a specific layer.
    • Border: Border color of a control on a specific layer.
    • Highlight: Background color when hovering.
    • HighlightBorder: Border color when hovering.
    • IntenseHighlight: Background color for the cursor spotlight.
    • IntenseHighlightBorder: Border color for the cursor spotlight.
    • Interaction: Background color when clicking a control.
    • InteractionBorder: Border color when clicking a control.
    • InteractionForeground: Foreground color when clicking a control.
  3. Configure Scroll Bar Expansion Mode

    master

    Adonis UI features an expand/collapse mechanic for scroll bars. By default (ExpandOnHover), scroll bars appear slim and without buttons, expanding to a normal size when the cursor enters their space. You can control this behavior using the ExpansionMode enum.

    ExpansionMode values:

    • AlwaysExpand: The scroll bar is always expanded and never collapses.
    • ExpandOnHover: The scroll bar is collapsed by default and expands on mouse entry (default).
    • NeverExpand: The scroll bar is always collapsed and never expands.
    <!-- For ScrollBars -->
    <ScrollBar adonisExtensions:ScrollBarExtension.ExpansionMode="AlwaysExpand"/>
    
    <!-- For ScrollViewers or controls containing them (TextBox, ComboBox, etc.) -->
    <ComboBox adonisExtensions:ScrollViewerExtension.VerticalScrollBarExpansionMode="AlwaysExpand"
              adonisExtensions:ScrollViewerExtension.HorizontalScrollBarExpansionMode="NeverExpand"/>
  4. Apply Ripple foreground to complex content using ContentTemplate

    master

    The RippleExtension.ForegroundBrush works automatically for primitive types, strings, and structs. However, for complex content (like child controls inside a button), the foreground brush will not be applied because the content cannot be easily duplicated for the ripple layer.

    To ensure the foreground brush is applied to complex content, you must use a ContentTemplate instead of setting the Content property directly. This allows the UI to instantiate the content multiple times (once for the normal layer and once for the ripple layer).

    For controls that do not natively have a ContentTemplate property, Adonis UI provides an attached property:

    • MenuItemExtension.IconTemplate: Use this to serve the icon of a MenuItem as a DataTemplate.
  5. How the layering system works

    master

    Adonis UI features a layering system that automatically adjusts the colors of UI controls based on the depth of nesting. This prevents visibility issues (such as low color contrast) when controls are placed inside containers with different background colors.

    By default, a window starts on layer 0, and all UI controls within it are placed on layer 1. When a container is assigned a higher layer, its children inherit that layer level (e.g., children of a layer 1 container move to layer 2). The system currently supports nesting up to layer 4.

    To use this system, you can either allow specific controls to increase the layer automatically or force a specific layer value using the LayerExtension.

  6. How data validation is displayed in Adonis UI

    master

    Adonis UI leverages standard WPF validation mechanisms (IDataErrorInfo or INotifyDataErrorInfo) to provide visual feedback. When a control is bound to an invalid property, the control template displays a red border and an error icon. The associated error message is shown in a popup when the control receives keyboard focus or when the user hovers over the error icon.

    Supported controls include:

    • CheckBox
    • ComboBox
    • DatePicker
    • PasswordBox
    • TextBox
  7. Localize MessageBox button labels

    master

    Adonis UI MessageBox does not automatically localize button labels using system language packs; it uses English by default. To support localization, you must manually override the labels when defining your buttons in the MessageBoxModel.

    var messageBox = new MessageBoxModel
    {
        Text = "Hallo welt!",
        Buttons = MessageBoxButtons.YesNoCancel("Ja", "Nein", "Abbrechen"),
    };
    
    MessageBox.Show(messageBox);
  8. Use AdonisWindow for custom title bars

    master

    To use the custom Adonis UI title bar, all your window classes must derive from AdonisUI.Controls.AdonisWindow.

    Note that this is a complete rebuild of the title bar that mimics the Windows 10 look. It is not controlled by the operating system, so it will maintain this appearance across all operating systems (e.g., it will not switch to the Windows 7 aero style on Windows 7).

  9. Assign Colors and Brushes in XAML

    master

    To use Adonis UI colors or brushes in your XAML, you must first include the Adonis UI namespace: xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI".

    Use DynamicResource with the static resource keys provided by the library to ensure colors update correctly when themes change.

    • To use a color: Color="{DynamicResource {x:Static adonisUi:Colors.Layer1BackgroundColor}}"
    • To use a brush: Background="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}"
  10. Use the Space markup extension for consistent layout spacing

    master

    Adonis UI provides a Space markup extension to ensure consistent spacing (margins, paddings, rows, columns) throughout your application. By default, the base unit for space is 8.

    Values can be provided as factors of this base unit. If an expression contains a + or -, the first value is the factor multiplied by the base unit, and the second value is treated as an absolute offset.

    Examples of usage:

    • Space 1 equals 8.
    • Space 2.5 equals 20.
    • Space 2.5+1 equals 21 (20 + 1).
    • Space 2.5-1 equals 19 (20 - 1).
    <!-- xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI" -->
    
    <RowDefinition Height="{adonisUi:Space 1}"/> <!-- equals Height="8" -->
    <RowDefinition Height="{adonisUi:Space 2.5}"/> <!-- equals Height="20" -->
    <RowDefinition Height="{adonisUi:Space 2.5+1}"/> <!-- equals Height="21" -->
    <RowDefinition Height="{adonisUi:Space 2.5-1}"/> <!-- equals Height="19" />
  11. Use built-in Loading Indicators

    master

    Adonis UI provides several built-in loading indicators as DataTemplates that can be applied to a ContentControl. The available indicators are:

    • LoadingCircle
    • LoadingBars
    • LoadingDots

    These templates are scalable and automatically inherit the Foreground brush from their parent control. To use them, reference them via adonisUi:Templates using a DynamicResource.

    <ContentControl ContentTemplate="{DynamicResource {x:Static adonisUi:Templates.LoadingCircle}}"
                    Foreground="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}"
                    Width="24"
                    Height="24"
                    Focusable="False"/>