Skip to content

Commit 81a3cfd

Browse files
committed
fix: ListViewItem incorrect default system style; feat: add option to change app theme;
1 parent 3d40c69 commit 81a3cfd

34 files changed

+739
-290
lines changed

BetterLyrics.WinUI3/App.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public App()
4545

4646
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
4747
{
48+
// 必须,加上此行以防止 SyncTheme 时线程被阻塞(原因未明)
49+
_ = Ioc.Default.GetRequiredService<ISettingsService>();
50+
4851
var splashWindow = WindowHook.OpenOrShowWindow<SplashWindow>();
4952
GlobalToastManager.Initialize();
5053

BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<None Remove="Controls\StatsDashboardControl.xaml" />
7070
<None Remove="Controls\SystemTray.xaml" />
7171
<None Remove="Controls\WindowSettingsControl.xaml" />
72+
<None Remove="Themes\DefaultListViewItemStyle.xaml" />
7273
<None Remove="Themes\DefaultStyles.xaml" />
7374
<None Remove="Themes\FluentAccentButtonStyle.xaml" />
7475
<None Remove="Themes\FluentButtonStyle.xaml" />
@@ -482,6 +483,11 @@
482483
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
483484
</Content>
484485
</ItemGroup>
486+
<ItemGroup>
487+
<Page Update="Themes\DefaultListViewItemStyle.xaml">
488+
<Generator>MSBuild:Compile</Generator>
489+
</Page>
490+
</ItemGroup>
485491
<ItemGroup>
486492
<Page Update="Themes\FluentListViewItemStyle.xaml">
487493
<Generator>MSBuild:Compile</Generator>

BetterLyrics.WinUI3/Controls/AppSettingsControl.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323

2424
<TextBlock x:Uid="SettingsPageAppAppearance" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
2525

26+
<controls:SettingsCard x:Uid="AppSettingsControlTheme" HeaderIcon="{ui:FontIcon FontFamily={StaticResource SegoeFluentIcons}, Glyph=&#xE790;}">
27+
<ComboBox x:Name="ThemeComboBox" SelectedIndex="{x:Bind ViewModel.AppSettings.GeneralSettings.AppTheme, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
28+
<ComboBoxItem x:Uid="SettingsPageFollowSystem" />
29+
<ComboBoxItem x:Uid="SettingsPageLight" />
30+
<ComboBoxItem x:Uid="SettingsPageDark" />
31+
</ComboBox>
32+
</controls:SettingsCard>
33+
2634
<controls:SettingsExpander
2735
x:Uid="SettingsPageLanguage"
2836
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SegoeFluentIcons},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.UI.Windowing;
2+
using Microsoft.UI.Xaml;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace BetterLyrics.WinUI3.Extensions
8+
{
9+
public static class ElementThemeExtensions
10+
{
11+
extension(ElementTheme elementTheme)
12+
{
13+
public TitleBarTheme ToTitleBarTheme() => elementTheme switch
14+
{
15+
ElementTheme.Light => TitleBarTheme.Light,
16+
ElementTheme.Dark => TitleBarTheme.Dark,
17+
_ => TitleBarTheme.UseDefaultAppMode
18+
};
19+
}
20+
}
21+
}

BetterLyrics.WinUI3/Extensions/WindowExtensions.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using BetterLyrics.WinUI3.Enums;
22
using BetterLyrics.WinUI3.Helper;
3+
using BetterLyrics.WinUI3.Models.Settings;
34
using BetterLyrics.WinUI3.Services.LocalizationService;
5+
using BetterLyrics.WinUI3.Services.SettingsService;
46
using CommunityToolkit.Mvvm.DependencyInjection;
57
using Microsoft.UI.Windowing;
68
using Microsoft.UI.Xaml;
@@ -9,8 +11,6 @@ namespace BetterLyrics.WinUI3.Extensions
911
{
1012
public static class WindowExtensions
1113
{
12-
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
13-
1414
extension(Window window)
1515
{
1616
public void Init(
@@ -19,9 +19,11 @@ public void Init(
1919
TitleBarHeightOption titleBarHeightOption = TitleBarHeightOption.Standard,
2020
BackdropType backdropType = BackdropType.DesktopAcrylic)
2121
{
22+
var localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
23+
2224
if (titleKey != "")
2325
{
24-
window.Title = _localizationService.GetLocalizedString(titleKey);
26+
window.Title = localizationService.GetLocalizedString(titleKey);
2527
}
2628
if (title != "")
2729
{
@@ -36,6 +38,16 @@ public void Init(
3638
window.SystemBackdrop = SystemBackdropHelper.CreateSystemBackdrop(backdropType);
3739
}
3840

41+
public void SyncTheme()
42+
{
43+
var settingsService = Ioc.Default.GetRequiredService<ISettingsService>();
44+
if (settingsService == null || window == null || window.Content == null) return;
45+
46+
var appTheme = settingsService.AppSettings.GeneralSettings.AppTheme;
47+
window.AppWindow.TitleBar.PreferredTheme = appTheme.ToTitleBarTheme();
48+
((FrameworkElement)window.Content).RequestedTheme = appTheme;
49+
}
50+
3951
}
4052
}
4153
}

BetterLyrics.WinUI3/Models/Settings/GeneralSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
2+
using Microsoft.UI.Xaml;
23
using System;
34
using System.Collections.Generic;
45

@@ -22,6 +23,7 @@ public partial class GeneralSettings : ObservableRecipient
2223
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool MultiNowPlayingWindowMode { get; set; } = false;
2324
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool AutoStartLyricsWindow { get; set; } = true;
2425
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool EnhanceControlInteractiveAnimations { get; set; } = true;
26+
[ObservableProperty][NotifyPropertyChangedRecipients] public partial ElementTheme AppTheme { get; set; } = ElementTheme.Default;
2527

2628
[ObservableProperty][NotifyPropertyChangedRecipients] public partial DateTime LastAppUpateCheckDateTime { get; set; } = DateTime.Now;
2729

BetterLyrics.WinUI3/Strings/ar/Resources.resw

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,46 +59,46 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
63-
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
6666
<xsd:choice maxOccurs="unbounded">
6767
<xsd:element name="metadata">
6868
<xsd:complexType>
6969
<xsd:sequence>
70-
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
7171
</xsd:sequence>
72-
<xsd:attribute name="name" use="required" type="xsd:string"/>
73-
<xsd:attribute name="type" type="xsd:string"/>
74-
<xsd:attribute name="mimetype" type="xsd:string"/>
75-
<xsd:attribute ref="xml:space"/>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
7676
</xsd:complexType>
7777
</xsd:element>
7878
<xsd:element name="assembly">
7979
<xsd:complexType>
80-
<xsd:attribute name="alias" type="xsd:string"/>
81-
<xsd:attribute name="name" type="xsd:string"/>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
8282
</xsd:complexType>
8383
</xsd:element>
8484
<xsd:element name="data">
8585
<xsd:complexType>
8686
<xsd:sequence>
87-
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
88-
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
8989
</xsd:sequence>
90-
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
91-
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
92-
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
93-
<xsd:attribute ref="xml:space"/>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
9494
</xsd:complexType>
9595
</xsd:element>
9696
<xsd:element name="resheader">
9797
<xsd:complexType>
9898
<xsd:sequence>
99-
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100100
</xsd:sequence>
101-
<xsd:attribute name="name" type="xsd:string" use="required"/>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102102
</xsd:complexType>
103103
</xsd:element>
104104
</xsd:choice>
@@ -165,6 +165,9 @@
165165
<data name="AppSettingsControlGeneral.Text" xml:space="preserve">
166166
<value>النافذة</value>
167167
</data>
168+
<data name="AppSettingsControlTheme.Header" xml:space="preserve">
169+
<value>App Theme</value>
170+
</data>
168171
<data name="AppUpdateServiceNewVersionAvailable" xml:space="preserve">
169172
<value>يتوفر الآن إصدار جديد من BetterLyrics</value>
170173
</data>

BetterLyrics.WinUI3/Strings/de/Resources.resw

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,46 +59,46 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
63-
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
6666
<xsd:choice maxOccurs="unbounded">
6767
<xsd:element name="metadata">
6868
<xsd:complexType>
6969
<xsd:sequence>
70-
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
7171
</xsd:sequence>
72-
<xsd:attribute name="name" use="required" type="xsd:string"/>
73-
<xsd:attribute name="type" type="xsd:string"/>
74-
<xsd:attribute name="mimetype" type="xsd:string"/>
75-
<xsd:attribute ref="xml:space"/>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
7676
</xsd:complexType>
7777
</xsd:element>
7878
<xsd:element name="assembly">
7979
<xsd:complexType>
80-
<xsd:attribute name="alias" type="xsd:string"/>
81-
<xsd:attribute name="name" type="xsd:string"/>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
8282
</xsd:complexType>
8383
</xsd:element>
8484
<xsd:element name="data">
8585
<xsd:complexType>
8686
<xsd:sequence>
87-
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
88-
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
8989
</xsd:sequence>
90-
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
91-
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
92-
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
93-
<xsd:attribute ref="xml:space"/>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
9494
</xsd:complexType>
9595
</xsd:element>
9696
<xsd:element name="resheader">
9797
<xsd:complexType>
9898
<xsd:sequence>
99-
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100100
</xsd:sequence>
101-
<xsd:attribute name="name" type="xsd:string" use="required"/>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102102
</xsd:complexType>
103103
</xsd:element>
104104
</xsd:choice>
@@ -165,6 +165,9 @@
165165
<data name="AppSettingsControlGeneral.Text" xml:space="preserve">
166166
<value>Fenster</value>
167167
</data>
168+
<data name="AppSettingsControlTheme.Header" xml:space="preserve">
169+
<value>App Theme</value>
170+
</data>
168171
<data name="AppUpdateServiceNewVersionAvailable" xml:space="preserve">
169172
<value>Eine neue Version von BetterLyrics ist verfügbar</value>
170173
</data>

BetterLyrics.WinUI3/Strings/en/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@
165165
<data name="AppSettingsControlGeneral.Text" xml:space="preserve">
166166
<value>Window</value>
167167
</data>
168+
<data name="AppSettingsControlTheme.Header" xml:space="preserve">
169+
<value>App Theme</value>
170+
</data>
168171
<data name="AppUpdateServiceNewVersionAvailable" xml:space="preserve">
169172
<value>A new version of BetterLyrics is available</value>
170173
</data>

BetterLyrics.WinUI3/Strings/es/Resources.resw

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,46 +59,46 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
63-
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
6666
<xsd:choice maxOccurs="unbounded">
6767
<xsd:element name="metadata">
6868
<xsd:complexType>
6969
<xsd:sequence>
70-
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
7171
</xsd:sequence>
72-
<xsd:attribute name="name" use="required" type="xsd:string"/>
73-
<xsd:attribute name="type" type="xsd:string"/>
74-
<xsd:attribute name="mimetype" type="xsd:string"/>
75-
<xsd:attribute ref="xml:space"/>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
7676
</xsd:complexType>
7777
</xsd:element>
7878
<xsd:element name="assembly">
7979
<xsd:complexType>
80-
<xsd:attribute name="alias" type="xsd:string"/>
81-
<xsd:attribute name="name" type="xsd:string"/>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
8282
</xsd:complexType>
8383
</xsd:element>
8484
<xsd:element name="data">
8585
<xsd:complexType>
8686
<xsd:sequence>
87-
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
88-
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
8989
</xsd:sequence>
90-
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
91-
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
92-
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
93-
<xsd:attribute ref="xml:space"/>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
9494
</xsd:complexType>
9595
</xsd:element>
9696
<xsd:element name="resheader">
9797
<xsd:complexType>
9898
<xsd:sequence>
99-
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100100
</xsd:sequence>
101-
<xsd:attribute name="name" type="xsd:string" use="required"/>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102102
</xsd:complexType>
103103
</xsd:element>
104104
</xsd:choice>
@@ -165,6 +165,9 @@
165165
<data name="AppSettingsControlGeneral.Text" xml:space="preserve">
166166
<value>Ventana</value>
167167
</data>
168+
<data name="AppSettingsControlTheme.Header" xml:space="preserve">
169+
<value>App Theme</value>
170+
</data>
168171
<data name="AppUpdateServiceNewVersionAvailable" xml:space="preserve">
169172
<value>Disponible una nueva versión de BetterLyrics</value>
170173
</data>

0 commit comments

Comments
 (0)