Skip to content

Theming & Dark Mode ​

Token model ​

The native bloodline's token source of truth lives in lh-ui-core/tokens/*.json; codegen produces the Windows artifacts (src/Tokens/, generated and gitignored, synced by pnpm link:tokens):

ArtifactContentsDark form
LhTokensFull light set: Button sizes, Color palette, Motion, Radius, Shadow, Spacing, Typography, ZIndex—
LhDarkTokensOnly the Color subclass (parallel-object model)Dark covers colors only; sizes / motion / corner radii are unchanged in dark
LhShadowShadow carrier (color/radius/offsetX/offsetY/spread)—
LhEasingMotion easing—

This matches android / ios / harmony (parallel objects) and differs from the docs end (shallow-merged JSON). The theme layer is designed accordingly: the LhColors record carries colors only, while sizes are taken straight from LhTokens by the components.

LhColors ​

LhColorsFactory.Light() / Dark() flatten the two generated static classes into a single immutable record:

csharp
public sealed record LhColors
{
    public Color Primary { get; init; }
    public Color OnPrimary { get; init; }
    // ... all semantic colors
}

public static class LhColorsFactory
{
    public static LhColors Light() => new()
    {
        Primary = LhTokens.Color.Primary.Default,
        // ...
    };

    public static LhColors Dark() => new()
    {
        Primary = LhDarkTokens.Color.Primary.Default,
        // ...
    };
}

The factory methods are public: xUnit tests can construct the palettes directly for assertions (see each suite's Dark_Colors_Come_From_Dark_Tokens); the app side consumes them through LhTheme.

LhTheme.Apply ​

csharp
LhTheme.Apply(isDark);  // Switches the palette and fires ThemeChanged

Components subscribe to LhTheme.ThemeChanged on Loaded and unsubscribe on Unloaded; on the event they call ApplyAppearance() to recompute and repaint — hot theme switching, no page-tree rebuild needed. Before any Apply, LhTheme.Current falls back to the light palette.

Dark pre-computation (important) ​

The web bloodline evaluates dark colors dynamically with CSS color-mix(); native has no CSS cascade, so core has pre-computed the dark expressions into literals (Color constants in #AARRGGBB form). Consequence (master plan R-n6):

When you change the preset primary color, the pre-computed dark values do not follow automatically — you must recompute and update lh-ui-core/tokens/color-dark.json by hand and refresh the Design Language Baseline accordingly.

Windows-specific conventions ​

  • Sizes are in epx: LhEpx.Px(token) marks a token value as effective pixels (WinUI effective pixels depend on the scale factor; everything goes through the marker function, and no bare numeric literals appear inside components).
  • The color type is Windows.UI.Color: every LhColors field is a Color; components wrap brushes as SolidColorBrush, and #AARRGGBB values are emitted by codegen directly as Color.FromArgb(...).
  • Font weights need mapping: the typography.fontWeight.* tokens are numbers while WinUI's FontWeights are predefined constants — everything goes through LhFontWeight.FromToken(token) (Common/LhFontWeight.cs).
  • Shadows go through Elevation: the Dialog content card / Picker panel express elevation with Border.Elevation + ThemeShadow (the Fluent language: flat buttons, floating layers cast shadows).
  • Focus visuals: a focused input box uses the focus color plus an input.focusRingWidth stroke (WinUI's high-visibility FocusVisualKind ring).

Token quick reference ​

The full token table (light/dark/notes) lives in the core repo's dist/docs/tokens.md (generated by pnpm codegen). For component-level token mappings see the Button token reference.

lh-ui native bloodline · Windows (C# + WinUI 3)