Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding highcontrast resources #802

Merged
merged 27 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Wpf.Ui.Gallery/Controls/ControlExample.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,31 @@
Grid.Row="0"
Margin="0,0,0,10"
FontTypography="BodyStrong"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Text="{TemplateBinding HeaderText}"
Visibility="{TemplateBinding HeaderText,
Converter={StaticResource NullToVisibilityConverter}}" />

<Border
Grid.Row="1"
Padding="16"
Background="{ui:ThemeResource CardStrokeColorDefaultBrush}"
BorderBrush="{ui:ThemeResource ControlElevationBorderBrush}"
Background="{ui:ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ui:ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1,1,1,0"
CornerRadius="8,8,0,0">
<ContentPresenter Content="{TemplateBinding ExampleContent}" />
</Border>

<ui:CardExpander
Grid.Row="2"
Background="{ui:ThemeResource CardBackgroundFillColorSecondaryBrush}"
CornerRadius="0,0,8,8"
Header="Source code">
<StackPanel>
<StackPanel x:Name="XamlCodeBlock">
<ui:TextBlock
Margin="0,0,0,5"
FontTypography="BodyStrong"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Text="XAML" />

<syntax:CodeBlock
Expand All @@ -63,14 +64,14 @@
<Border
x:Name="Border"
Margin="0,20"
BorderBrush="{ui:ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderThickness="1"
Visibility="Visible" />

<StackPanel x:Name="CsharpCodeBlock">
<ui:TextBlock
Margin="0,0,0,5"
FontTypography="BodyStrong"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Text="C#" />

<syntax:CodeBlock
Expand Down
11 changes: 8 additions & 3 deletions src/Wpf.Ui.Gallery/Controls/GalleryNavigationPresenter.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ResourceDictionary
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basicInput="clr-namespace:Wpf.Ui.Gallery.Views.Pages.BasicInput"
Expand All @@ -24,16 +24,21 @@
CommandParameter="{Binding PageType, Mode=OneTime}"
IsChevronVisible="True">
<ui:CardAction.Icon>
<ui:SymbolIcon FontSize="30" Symbol="{Binding Icon, Mode=OneTime}" />
<ui:SymbolIcon
FontSize="30"
Symbol="{Binding Icon, Mode=OneTime}"
TextElement.Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
</ui:CardAction.Icon>
<StackPanel>
<ui:TextBlock
Margin="0"
FontTypography="BodyStrong"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Text="{Binding Name, Mode=OneTime}"
TextWrapping="WrapWithOverflow" />
<ui:TextBlock
Appearance="Tertiary"
Appearance="Secondary"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="{Binding Description, Mode=OneTime}"
TextWrapping="WrapWithOverflow" />
</StackPanel>
Expand Down
13 changes: 7 additions & 6 deletions src/Wpf.Ui.Gallery/Views/Pages/DashboardPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page
<Page
x:Class="Wpf.Ui.Gallery.Views.Pages.DashboardPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -117,7 +117,8 @@
Text="Basic input"
TextWrapping="WrapWithOverflow" />
<ui:TextBlock
Appearance="Tertiary"
Appearance="Secondary"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Buttons, CheckBoxes, Sliders..."
TextWrapping="WrapWithOverflow" />
</StackPanel>
Expand Down Expand Up @@ -154,8 +155,8 @@
Text="Dialogs &amp; Flyouts"
TextWrapping="WrapWithOverflow" />
<ui:TextBlock
Appearance="Tertiary"
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
Appearance="Secondary"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Contextual notifications."
TextWrapping="WrapWithOverflow" />
</StackPanel>
Expand Down Expand Up @@ -192,8 +193,8 @@
Text="Navigation"
TextWrapping="WrapWithOverflow" />
<ui:TextBlock
Appearance="Tertiary"
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
Appearance="Secondary"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Managing the displayed pages."
TextWrapping="WrapWithOverflow" />
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
</ui:IconSourceElement>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="16" />
<Setter Property="FontWeight" Value="Regular" />
</Style>
</ResourceDictionary>
Expand Down
9 changes: 3 additions & 6 deletions src/Wpf.Ui.Gallery/Views/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
IsDesignTimeCreatable=False}"
d:DesignHeight="450"
d:DesignWidth="800"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">

<StackPanel Margin="0,0,0,24">
Expand All @@ -37,7 +34,7 @@
Text="App theme" />
<ui:TextBlock
Grid.Row="1"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="Select which app theme to display" />
</Grid>
</ui:CardControl.Header>
Expand Down Expand Up @@ -93,15 +90,15 @@
<ui:TextBlock
Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="© 2023 lepo.co | Leszek Pomianowski &amp; WPF UI Contributors" />
<TextBlock
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Margin="0,0,16,0"
VerticalAlignment="Center"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
Text="{Binding ViewModel.AppVersion, Mode=OneWay}" />
</Grid>
</ui:CardExpander.Header>
Expand Down
8 changes: 7 additions & 1 deletion src/Wpf.Ui.Gallery/Views/Pages/Windows/WindowsPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page
<Page
x:Class="Wpf.Ui.Gallery.Views.Pages.Windows.WindowsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -56,5 +56,11 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ui:Card
Margin="12"
VerticalAlignment="Bottom"
Footer="Asdasd">
<Button Content="Lala" />
</ui:Card>
</Grid>
</Page>
4 changes: 2 additions & 2 deletions src/Wpf.Ui.Gallery/Views/Windows/EditorWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ui:FluentWindow
<ui:FluentWindow
x:Class="Wpf.Ui.Gallery.Views.Windows.EditorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -238,7 +238,7 @@
<StackPanel>
<TextBlock FontWeight="Medium" Text="WPF UI - Editor" />
<TextBlock
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Congratulations, you clicked the button on the menu"
TextAlignment="Justify"
TextWrapping="WrapWithOverflow" />
Expand Down
9 changes: 9 additions & 0 deletions src/Wpf.Ui/Appearance/ApplicationThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Runtime.CompilerServices;
using Wpf.Ui.Controls;

namespace Wpf.Ui.Appearance;
Expand Down Expand Up @@ -93,6 +94,10 @@ public static void Apply(
case ApplicationTheme.Dark:
themeDictionaryName = "Dark";
break;
case ApplicationTheme.HighContrast:
themeDictionaryName = "HighContrast";
backgroundEffect = WindowBackdropType.None; // We want to disable the background effect in high contrast mode
break;
}

var isUpdated = appDictionaries.UpdateDictionary(
Expand Down Expand Up @@ -165,6 +170,10 @@ public static void ApplySystemTheme(bool updateAccent)
{
themeToSet = ApplicationTheme.Dark;
}
else if (systemTheme is SystemTheme.HC1 or SystemTheme.HC2 or SystemTheme.HCBlack or SystemTheme.HCWhite)
{
themeToSet = ApplicationTheme.HighContrast;
}

Apply(themeToSet);
}
Expand Down
20 changes: 20 additions & 0 deletions src/Wpf.Ui/Appearance/SystemTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ public enum SystemTheme
/// </summary>
Dark,

/// <summary>
/// High-contrast theme: Desert
/// </summary>
HCWhite,

/// <summary>
/// High-contrast theme: Acquatic
/// </summary>
HCBlack,

/// <summary>
/// High-contrast theme: Dusk
/// </summary>
HC1,

/// <summary>
/// High-contrast theme: Nightsky
/// </summary>
HC2,

/// <summary>
/// First custom, kinda purple Windows 11 theme.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/Wpf.Ui/Appearance/SystemThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ private static SystemTheme GetCurrentSystemTheme()
return SystemTheme.Dark;
}

if (currentTheme.Contains("hcblack.theme"))
{
return SystemTheme.HC1;
}

if (currentTheme.Contains("hcwhite.theme"))
{
return SystemTheme.HCWhite;
}

if (currentTheme.Contains("hc1.theme"))
{
return SystemTheme.HC1;
}

if (currentTheme.Contains("hc2.theme"))
{
return SystemTheme.HC2;
}

if (currentTheme.Contains("themea.theme"))
{
return SystemTheme.Glow;
Expand Down
28 changes: 5 additions & 23 deletions src/Wpf.Ui/Controls/BreadcrumbBar/BreadcrumbBar.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
Expand All @@ -11,17 +11,8 @@
xmlns:controls="clr-namespace:Wpf.Ui.Controls">

<Style x:Key="DefaultUiBreadcrumbButtonStyle" TargetType="{x:Type ButtonBase}">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorTertiary}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{DynamicResource BreadcrumbBarNormalForegroundBrush}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextOnAccentFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
Expand All @@ -35,11 +26,7 @@
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Presenter" Property="TextElement.Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter TargetName="Presenter" Property="TextElement.Foreground" Value="{DynamicResource BreadcrumbBarHoverForegroundBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False" />
</ControlTemplate.Triggers>
Expand All @@ -49,7 +36,7 @@
</Style>

<Style x:Key="DefaultUiBreadcrumbBarItemStyle" TargetType="{x:Type controls:BreadcrumbBarItem}">
<Setter Property="FontSize" Value="28" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="DemiBold" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
Expand Down Expand Up @@ -102,12 +89,7 @@

<ControlTemplate.Triggers>
<Trigger Property="IsLast" Value="True">
<Setter TargetName="Button" Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>

<Setter TargetName="Button" Property="Foreground" Value="{DynamicResource BreadcrumbBarCurrentNormalForegroundBrush}" />
<Setter TargetName="Button" Property="IsEnabled" Value="False" />
<Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
</Trigger>
Expand Down
Loading
Loading