lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.47k stars 725 forks source link

[Proposal] Better support for High Contrast themes + better resource management #777

Closed niels9001 closed 10 months ago

niels9001 commented 12 months ago

Is your feature request related to a problem? Please describe

Currently, High Contrast support is severely lacking - and does not provide a great experience for users needing it. Colors do not match recommended guidelines. Just adding the brush equivalents in HighContrast.xaml is not enough, as core brushes.

An example:

Button uses ControlFillColorSecondaryBrush as its MouseOver state - but this brush is used in many controls.

To support proper high-contrast, this brush should be overwritten - but the color that needs to be used would be different for e.g. Button.

Describe the solution you'd like

Instead of using brushes like ControlFillColorSecondaryBrush directly in the Button.xaml, we'd need to create a ButtonBackgroundPointerOver brush, that enherites ControlFillColorSecondaryBrush.

This means that Button.xaml would have Button-specific brushes only and these brushes would live in Dark.xaml, Light.xaml and HighContrast.xaml. This would allow us to override the brush resources with the correct colors for high-contrast mode.

Button.xaml now (Pressed state):

<ControlTemplate.Triggers>
    <Trigger Property="IsPressed" Value="True">
        <Setter Property="Background" Value="{DynamicResource ControlFillColorTertiaryBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
        <Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource TextFillColorSecondaryBrush}" />
    </Trigger>
</ControlTemplate.Triggers>

Button.xaml proposed:

<ControlTemplate.Triggers>
    <Trigger Property="IsPressed" Value="True">
        <Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushPressed}" />
        <Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ButtonForegroundPressed}" />
    </Trigger>
</ControlTemplate.Triggers>

In Dark.xaml, Light.xaml and HighContrast.xaml we'd define these brushes as:

<!-- Button brushes -->
 <StaticResource x:Key="ButtonBackgroundPressed" ResourceKey="ControlFillColorTertiaryBrush" />
 <StaticResource x:Key="ButtonBorderBrushPressed" ResourceKey="ControlStrokeColorDefaultBrush" />
 <StaticResource x:Key="ButtonForegroundPressed" ResourceKey="TextFillColorSecondaryBrush" />

Describe alternatives you've considered

No response

Additional context

Ideally we'd have ThemeDictionary in control specific style sheets (like WinUI), but since these are not supported we'd need to have these in the main resource dictionaries.

niels9001 commented 12 months ago

@pomianowski FYI

niels9001 commented 10 months ago

Resolved in #788