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):
| Artifact | Contents | Dark form |
|---|---|---|
LhTokens | Full light set: Button sizes, Color palette, Motion, Radius, Shadow, Spacing, Typography, ZIndex | — |
LhDarkTokens | Only the Color subclass (parallel-object model) | Dark covers colors only; sizes / motion / corner radii are unchanged in dark |
LhShadow | Shadow carrier (color/radius/offsetX/offsetY/spread) | — |
LhEasing | Motion easing | — |
This matches android / ios / harmony (parallel objects) and differs from the docs end (shallow-merged JSON). The theme layer is designed accordingly: the
LhColorsrecord carries colors only, while sizes are taken straight fromLhTokensby the components.
LhColors
LhColorsFactory.Light() / Dark() flatten the two generated static classes into a single immutable record:
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
LhTheme.Apply(isDark); // Switches the palette and fires ThemeChangedComponents 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.jsonby 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: everyLhColorsfield is aColor; components wrap brushes asSolidColorBrush, and#AARRGGBBvalues are emitted by codegen directly asColor.FromArgb(...). - Font weights need mapping: the
typography.fontWeight.*tokens are numbers while WinUI'sFontWeightsare predefined constants — everything goes throughLhFontWeight.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
focuscolor plus aninput.focusRingWidthstroke (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.

