WPF: Add light/dark theme swtich

This commit is contained in:
genteure 2022-04-16 01:54:43 +08:00
parent 669da1d39a
commit 10adc77f9e
3 changed files with 46 additions and 17 deletions

View File

@ -55,6 +55,7 @@
IsPaneOpen="False" OpenPaneLength="200"
SelectionChanged="NavigationView_SelectionChanged">
<ui:NavigationView.PaneCustomContent>
<StackPanel>
<Menu>
<MenuItem>
<MenuItem.Header>
@ -73,6 +74,14 @@
</MenuItem>
</MenuItem>
</Menu>
<Menu>
<MenuItem Click="SwitchLightDarkTheme_Click">
<MenuItem.Header>
<ui:PathIcon Width="16" Height="16" Style="{StaticResource PathIconDataThemeLightDark}"/>
</MenuItem.Header>
</MenuItem>
</Menu>
</StackPanel>
</ui:NavigationView.PaneCustomContent>
<ui:NavigationView.PaneFooter>
<Grid Width="40" Height="40" x:Name="DebugBuildIcon" Visibility="Collapsed" HorizontalAlignment="Left">

View File

@ -13,6 +13,7 @@ using BililiveRecorder.DependencyInjection;
using BililiveRecorder.WPF.Controls;
using BililiveRecorder.WPF.Models;
using Microsoft.Extensions.DependencyInjection;
using ModernWpf;
using ModernWpf.Controls;
using ModernWpf.Media.Animation;
using Serilog;
@ -338,5 +339,21 @@ You can uninstall me in system settings.", "安装成功 Installed", MessageBoxB
{
}
}
private void SwitchLightDarkTheme_Click(object sender, RoutedEventArgs e)
{
if (this.Dispatcher.CheckAccess())
changeTheme();
else
_ = this.Dispatcher.BeginInvoke(changeTheme);
static void changeTheme()
{
ThemeManager.Current.ApplicationTheme =
ThemeManager.Current.ActualApplicationTheme == ApplicationTheme.Dark
? ApplicationTheme.Light
: ApplicationTheme.Dark;
};
}
}
}

View File

@ -97,6 +97,9 @@
<Style TargetType="ui:PathIcon" x:Key="PathIconDataMerge">
<Setter Property="Data" Value="M8 17L12 13H15.2C15.6 14.2 16.7 15 18 15C19.7 15 21 13.7 21 12S19.7 9 18 9C16.7 9 15.6 9.8 15.2 11H12L8 7V3H3V8H6L10.2 12L6 16H3V21H8V17Z"/>
</Style>
<Style TargetType="ui:PathIcon" x:Key="PathIconDataThemeLightDark">
<Setter Property="Data" Value="M7.5,2C5.71,3.15 4.5,5.18 4.5,7.5C4.5,9.82 5.71,11.85 7.53,13C4.46,13 2,10.54 2,7.5A5.5,5.5 0 0,1 7.5,2M19.07,3.5L20.5,4.93L4.93,20.5L3.5,19.07L19.07,3.5M12.89,5.93L11.41,5L9.97,6L10.39,4.3L9,3.24L10.75,3.12L11.33,1.47L12,3.1L13.73,3.13L12.38,4.26L12.89,5.93M9.59,9.54L8.43,8.81L7.31,9.59L7.65,8.27L6.56,7.44L7.92,7.35L8.37,6.06L8.88,7.33L10.24,7.36L9.19,8.23L9.59,9.54M19,13.5A5.5,5.5 0 0,1 13.5,19C12.28,19 11.15,18.6 10.24,17.93L17.93,10.24C18.6,11.15 19,12.28 19,13.5M14.6,20.08L17.37,18.93L17.13,22.28L14.6,20.08M18.93,17.38L20.08,14.61L22.28,17.15L18.93,17.38M20.08,12.42L18.94,9.64L22.28,9.88L20.08,12.42M9.63,18.93L12.4,20.08L9.87,22.27L9.63,18.93Z"/>
</Style>
<Style TargetType="ui:PathIcon" x:Key="PathIconData">
<Setter Property="Data" Value=""/>
</Style>