Skip to content

Commit

Permalink
Merge pull request #144 from wokhan/imp_themes_accessibility
Browse files Browse the repository at this point in the history
Improved theming and accessibility
  • Loading branch information
wokhan authored Jan 1, 2023
2 parents 381e1a2 + 8580fd7 commit 367bf21
Show file tree
Hide file tree
Showing 38 changed files with 1,031 additions and 785 deletions.
2 changes: 1 addition & 1 deletion Common.Tests/Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Wokhan.Core" Version="0.9.2-alpha" />
<PackageReference Include="Wokhan.Core" Version="0.9.4-beta" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
Expand Down
3 changes: 3 additions & 0 deletions Common/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
<setting name="ShowConnections" serializeAs="String">
<value>True</value>
</setting>
<setting name="Theme" serializeAs="String">
<value />
</setting>
</Wokhan.WindowsFirewallNotifier.Common.Config.Settings>
</userSettings>
<applicationSettings>
Expand Down
4 changes: 2 additions & 2 deletions Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="Wokhan.Core" Version="0.9.2-alpha" />
<PackageReference Include="Wokhan.UI" Version="0.9.2-alpha" />
<PackageReference Include="Wokhan.Core" Version="0.9.4-beta" />
<PackageReference Include="Wokhan.UI" Version="0.9.8-beta" />
</ItemGroup>
<ItemGroup>
<Reference Include="Interop.NetFwTypeLib">
Expand Down
20 changes: 16 additions & 4 deletions Common/Config/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Common/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Settings() //: base()
PropertyChanged += Settings_PropertyChanged;
}

private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
private void Settings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
Expand Down
7 changes: 5 additions & 2 deletions Common/Config/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Setting Name="EnableServiceDetectionGlobal" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ConsoleSizeHeight" Type="System.Int32" Scope="User">
<Setting Name="ConsoleSizeHeight" Type="System.Double" Scope="User">
<Value Profile="(Default)">600</Value>
</Setting>
<Setting Name="ConsoleState" Type="System.Windows.WindowState" Scope="User">
Expand All @@ -32,7 +32,7 @@
<Setting Name="MinimizeToTray" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ConsoleSizeWidth" Type="System.Int32" Scope="User">
<Setting Name="ConsoleSizeWidth" Type="System.Double" Scope="User">
<Value Profile="(Default)">900</Value>
</Setting>
<Setting Name="EnableVerboseLogging" Type="System.Boolean" Scope="User">
Expand Down Expand Up @@ -86,5 +86,8 @@
<Setting Name="ShowConnections" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Theme" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
43 changes: 25 additions & 18 deletions Common/UI/Theme.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ext="clr-namespace:Wokhan.UI.Xaml.Extensibility;assembly=Wokhan.UI">

<SolidColorBrush x:Key="AccentColorBrush" Color="{DynamicResource SystemParameters.WindowGlassColor}" />

<Style TargetType="CheckBox">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Background" Value="{DynamicResource ButtonBackground}"/>
<Setter Property="BorderThickness" Value="2" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
<Setter Property="Template">
Expand Down Expand Up @@ -41,7 +44,7 @@

<Style TargetType="Button">
<Setter Property="ext:CustomAdorner.CornerRadius" Value="4" />
<Setter Property="Background" Value="WhiteSmoke" />
<Setter Property="Background" Value="{DynamicResource ButtonBackground}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="10,5" />
<Setter Property="Margin" Value="2" />
Expand All @@ -50,48 +53,43 @@
<Setter Property="Opacity" Value="0.6" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue" />
<Setter Property="Background" Value="{DynamicResource ButtonOverBackground}" />
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="ToggleButton">
<Setter Property="ext:CustomAdorner.CornerRadius" Value="4" />
<Setter Property="Background" Value="WhiteSmoke" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="{DynamicResource ButtonBackground}" />
<Setter Property="BorderThickness" Value="0 0 0 3" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBackground}" />
<Setter Property="Padding" Value="10,5" />
<Setter Property="Margin" Value="2" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.6" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="{DynamicResource AccentColorBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue" />
<Setter Property="Background" Value="{DynamicResource ButtonOverBackground}" />
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="ComboBox">
<Setter Property="ext:CustomAdorner.PreserveTemplate" Value="true" />
<Setter Property="ext:CustomAdorner.PreserveTemplate" Value="True" />
<Setter Property="IsEditable" Value="False" />
<Setter Property="Background" Value="WhiteSmoke" />
<!--<Setter Property="Background" Value="{DynamicResource ButtonBackground}" />-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton ext:CustomAdorner.HeaderImage="{Binding Path=(ext:CustomAdorner.HeaderImage),RelativeSource={x:Static RelativeSource.TemplatedParent}}" ext:CustomAdorner.Header="{Binding Path=(ext:CustomAdorner.Header),RelativeSource={x:Static RelativeSource.TemplatedParent}}" Content="{Binding Text,RelativeSource={x:Static RelativeSource.TemplatedParent}}" ext:CustomAdorner.Image="{Binding Path=(ext:CustomAdorner.Image),RelativeSource={x:Static RelativeSource.TemplatedParent}}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={x:Static RelativeSource.TemplatedParent}}">
<ToggleButton.Style>
<Style TargetType="ToggleButton" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="Background" Value="{Binding Background,RelativeSource={x:Static RelativeSource.TemplatedParent}}" />
</Style>
</ToggleButton.Style>
</ToggleButton>
<ToggleButton ext:CustomAdorner.HeaderImage="{Binding Path=(ext:CustomAdorner.HeaderImage),RelativeSource={x:Static RelativeSource.TemplatedParent}}" ext:CustomAdorner.Header="{Binding Path=(ext:CustomAdorner.Header),RelativeSource={x:Static RelativeSource.TemplatedParent}}" Content="{Binding Text,RelativeSource={x:Static RelativeSource.TemplatedParent}}" ext:CustomAdorner.Image="{Binding Path=(ext:CustomAdorner.Image),RelativeSource={x:Static RelativeSource.TemplatedParent}}" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={x:Static RelativeSource.TemplatedParent}}" />
<Popup x:Name="PART_Popup" IsOpen="{TemplateBinding IsDropDownOpen}" StaysOpen="False" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide" Placement="Bottom">
<Grid Background="{TemplateBinding Background}" MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}" Margin="4,0,4,4">
<Border Background="{TemplateBinding Background}" CornerRadius="4">
<Grid MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}" Margin="4,0,4,4">
<Border Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" CornerRadius="4">
<Border.Effect>
<DropShadowEffect Color="LightGray" ShadowDepth="2" />
</Border.Effect>
Expand All @@ -109,4 +107,13 @@
</Setter>
</Style>

<SolidColorBrush x:Key="WindowBrushSaved" Color="{x:Static SystemColors.WindowColor}" />
<SolidColorBrush x:Key="WindowTextBrushSaved" Color="{x:Static SystemColors.WindowTextColor}" />
<SolidColorBrush x:Key="ActiveCaptionBrushSaved" Color="{x:Static SystemColors.ActiveCaptionColor}" />
<SolidColorBrush x:Key="ScrollBarBrushSaved" Color="{x:Static SystemColors.ScrollBarColor}" />
<SolidColorBrush x:Key="MenuBarBrushSaved" Color="{x:Static SystemColors.MenuBarColor}" />
<SolidColorBrush x:Key="ControlTextBrushSaved" Color="{x:Static SystemColors.ControlTextColor}" />
<SolidColorBrush x:Key="ControlBrushSaved" Color="{x:Static SystemColors.ControlColor}" />
<SolidColorBrush x:Key="InfoBrushSaved" Color="{x:Static SystemColors.InfoColor}" />

</ResourceDictionary>
40 changes: 40 additions & 0 deletions Common/UI/Themes/Dark.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Theme.xaml" />
</ResourceDictionary.MergedDictionaries>

<SolidColorBrush x:Key="AccentColorBrush" Color="Coral" />
<SolidColorBrush x:Key="DataGridCellSelectedForeground" Color="Black" />
<SolidColorBrush x:Key="DataGridRowSelectedBackground" Color="SlateGray" />
<SolidColorBrush x:Key="DataGridRowAltBackground" Color="#101010" />

<SolidColorBrush x:Key="TabItemOverBackground" Color="#202020" />

<SolidColorBrush x:Key="ButtonBackground" Color="#303030" />
<SolidColorBrush x:Key="ButtonOverBackground" Color="#505050" />

<SolidColorBrush x:Key="StatusScreenPrivateBackgroundBrush" Color="DarkMagenta" Opacity="0.2" />
<SolidColorBrush x:Key="StatusScreenPublicBackgroundBrush" Color="DarkGreen" Opacity="0.2" />
<SolidColorBrush x:Key="StatusScreenDomainBackgroundBrush" Color="DarkBlue" Opacity="0.2" />
<SolidColorBrush x:Key="StatusScreenAllBackgroundBrush" Color="Gray" Opacity="0.2" />

<system:Double x:Key="{x:Static SystemParameters.CaptionHeightKey}">38</system:Double>

<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.WindowTextBrushKey}" Color="White" />
<SolidColorBrush x:Key="{x:Static SystemColors.ActiveCaptionBrushKey}" Color="#202020" />
<SolidColorBrush x:Key="{x:Static SystemColors.ScrollBarBrushKey}" Color="#202020" />
<SolidColorBrush x:Key="{x:Static SystemColors.MenuBarBrushKey}" Color="#101010" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="White" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#202020" />
<SolidColorBrush x:Key="{x:Static SystemColors.InfoBrushKey}" Color="Gray" />
<SolidColorBrush x:Key="{x:Static SystemColors.InfoTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Gray" />
<!--<SolidColorBrush x:Key="{x:Static SystemColors.ButtonHighlightBrushKey}" Color="#202020" />-->

<SolidColorBrush x:Key="{x:Static SystemColors.ControlLightBrushKey}" Color="Black" />

</ResourceDictionary>
40 changes: 40 additions & 0 deletions Common/UI/Themes/Light.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Theme.xaml" />
</ResourceDictionary.MergedDictionaries>

<SolidColorBrush x:Key="AccentColorBrush" Color="Coral" />
<SolidColorBrush x:Key="DataGridCellSelectedForeground" Color="Black" />
<SolidColorBrush x:Key="DataGridRowSelectedBackground" Color="LightBlue" />
<SolidColorBrush x:Key="DataGridRowAltBackground" Color="LightGray" />

<SolidColorBrush x:Key="TabItemOverBackground" Color="WhiteSmoke" />

<SolidColorBrush x:Key="ButtonBackground" Color="WhiteSmoke" />
<SolidColorBrush x:Key="ButtonOverBackground" Color="LightBlue" />

<SolidColorBrush x:Key="StatusScreenPrivateBackgroundBrush" Color="Lavender" />
<SolidColorBrush x:Key="StatusScreenPublicBackgroundBrush" Color="#FFC5FFC5" />
<SolidColorBrush x:Key="StatusScreenDomainBackgroundBrush" Color="#FFC1F4FF" />
<SolidColorBrush x:Key="StatusScreenAllBackgroundBrush" Color="LightGray" />

<system:Double x:Key="{x:Static SystemParameters.CaptionHeightKey}">38</system:Double>

<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="WhiteSmoke" />
<SolidColorBrush x:Key="{x:Static SystemColors.WindowTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ActiveCaptionBrushKey}" Color="LightGray" />
<SolidColorBrush x:Key="{x:Static SystemColors.ScrollBarBrushKey}" Color="WhiteSmoke" />
<SolidColorBrush x:Key="{x:Static SystemColors.MenuBarBrushKey}" Color="LightGray" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="White" />
<SolidColorBrush x:Key="{x:Static SystemColors.InfoBrushKey}" Color="LightYellow" />
<SolidColorBrush x:Key="{x:Static SystemColors.InfoTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Gray" />
<!--<SolidColorBrush x:Key="{x:Static SystemColors.ButtonHighlightBrushKey}" Color="#202020" />-->

<SolidColorBrush x:Key="{x:Static SystemColors.ControlLightBrushKey}" Color="Black" />

</ResourceDictionary>
26 changes: 26 additions & 0 deletions Common/UI/Themes/System.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Theme.xaml" />
</ResourceDictionary.MergedDictionaries>

<SolidColorBrush x:Key="AccentColorBrush" Color="{x:Static SystemParameters.WindowGlassColor}" />

<SolidColorBrush x:Key="DataGridCellSelectedForeground" Color="Black" />
<SolidColorBrush x:Key="DataGridRowSelectedBackground" Color="LightBlue" />

<SolidColorBrush x:Key="TabItemOverBackground" Color="{x:Static SystemColors.ControlColor}" />

<SolidColorBrush x:Key="ButtonBackground" Color="{x:Static SystemColors.ControlDarkColor}" />
<SolidColorBrush x:Key="ButtonOverBackground" Color="{x:Static SystemColors.ControlLightColor}" />

<system:Double x:Key="{x:Static SystemParameters.CaptionHeightKey}">38</system:Double>

<SolidColorBrush x:Key="StatusScreenPrivateBackgroundBrush" Color="{x:Static SystemColors.ControlColor}" />
<SolidColorBrush x:Key="StatusScreenPublicBackgroundBrush" Color="{x:Static SystemColors.ControlColor}" />
<SolidColorBrush x:Key="StatusScreenDomainBackgroundBrush" Color="{x:Static SystemColors.ControlColor}" />
<SolidColorBrush x:Key="StatusScreenAllBackgroundBrush" Color="{x:Static SystemColors.ControlColor}" />

</ResourceDictionary>
49 changes: 49 additions & 0 deletions Common/UI/Themes/ThemeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Microsoft.Win32;

using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;

using Wokhan.WindowsFirewallNotifier.Common.Config;

namespace Wokhan.WindowsFirewallNotifier.Common.UI.Themes
{
public static partial class ThemeHelper
{
public static string GetActiveTheme()
{
if (Settings.Default.Theme is null or "Automatic")
{
if (SystemParameters.HighContrast)
{
return "System";
}

using (RegistryKey? key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"))
{
return (int?)key?.GetValue("AppsUseLightTheme") == 0 ? "Dark" : "Light";
}
}
else
{
return Settings.Default.Theme;
}
}

public static string GetURIForCurrentTheme()
{
return $"pack://application:,,,/Wokhan.WindowsFirewallNotifier.Common;component/UI/Themes/{GetActiveTheme()}.xaml";
}

public static string GetURIForTheme(string themeName)
{
if (themeName == "Automatic")
{
return GetURIForCurrentTheme();
}

return $"pack://application:,,,/Wokhan.WindowsFirewallNotifier.Common;component/UI/Themes/{themeName}.xaml";
}
}
}
Loading

0 comments on commit 367bf21

Please sign in to comment.