Skip to content

Commit 68a4fb5

Browse files
committed
完善设置页面
1 parent 47ce80f commit 68a4fb5

25 files changed

+1842
-121
lines changed

.github/workflows/build-and-package.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
run: nuget restore $env:Solution_Name
6666

6767
# Create the app package by building and packaging the Windows Application Packaging project
68-
- name: Create the app package
68+
- name: Create the app package (x64)
6969
run: msbuild $env:Solution_Name `
7070
/p:AppxBundlePlatforms="$env:Appx_Bundle_Platforms" `
7171
/p:Configuration=$env:Configuration `
@@ -80,14 +80,37 @@ jobs:
8080
/p:PackageCertificatePassword="$env:Password"
8181
env:
8282
Appx_Bundle: Never
83-
Appx_Bundle_Platforms: x64|ARM64
83+
Appx_Bundle_Platforms: x64
8484
Appx_Package_Build_Mode: SideloadOnly
8585
Appx_Package_Dir: AppxPackages\
8686
Configuration: Release
8787
Platform: 'x64'
8888
Thumbprint: 0CDF4A03E9BE9DD789894BB3C7AD3DEDECD9AB25
8989
Password: ${{ secrets.Password }}
9090

91+
- name: Create the app package (ARM64)
92+
run: msbuild $env:Solution_Name `
93+
/p:AppxBundlePlatforms="$env:Appx_Bundle_Platforms" `
94+
/p:Configuration=$env:Configuration `
95+
/p:Platform=$env:Platform `
96+
/p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode `
97+
/p:AppxBundle=$env:Appx_Bundle `
98+
/p:AppxPackageDir="$env:Appx_Package_Dir" `
99+
/p:GenerateAppxPackageOnBuild=true `
100+
/p:AppxPackageSigningEnabled=true `
101+
/p:PackageCertificateThumbprint="$env:Thumbprint" `
102+
/p:PackageCertificateKeyFile=$env:Signing_Certificate `
103+
/p:PackageCertificatePassword="$env:Password"
104+
env:
105+
Appx_Bundle: Never
106+
Appx_Bundle_Platforms: ARM64
107+
Appx_Package_Build_Mode: SideloadOnly
108+
Appx_Package_Dir: AppxPackages\
109+
Configuration: Release
110+
Platform: 'ARM64'
111+
Thumbprint: 0CDF4A03E9BE9DD789894BB3C7AD3DEDECD9AB25
112+
Password: ${{ secrets.Password }}
113+
91114
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
92115
- name: Upload build artifacts
93116
uses: actions/upload-artifact@v4

CoreAppUAP/App.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
x:Class="CoreAppUAP.App"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:common="using:CoreAppUAP.Common"
56
xmlns:converters="using:CoreAppUAP.Helpers.Converters"
67
xmlns:local="using:CoreAppUAP">
78
<Application.Resources>
89
<ResourceDictionary>
10+
<ResourceDictionary.MergedDictionaries>
11+
<common:AccentColorResource />
12+
</ResourceDictionary.MergedDictionaries>
913
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
14+
<converters:StringVisibilityConverter x:Key="StringVisibilityConverter" />
1015
<FontFamily x:Key="SymbolThemeFontFamily">Segoe Fluent Icons,Segoe MDL2 Assets,Segoe UI Symbol</FontFamily>
1116
</ResourceDictionary>
1217
</Application.Resources>

CoreAppUAP/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void EnsureWindow(IActivatedEventArgs e)
126126
// 将框架放在当前窗口中
127127
window.Content = rootFrame;
128128

129-
//ThemeHelper.Initialize();
129+
ThemeHelper.Initialize();
130130
}
131131

132132
if (e is LaunchActivatedEventArgs args)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Windows.UI.ViewManagement;
2+
using Windows.UI.Xaml;
3+
4+
namespace CoreAppUAP.Common
5+
{
6+
public partial class AccentColorResource : ResourceDictionary
7+
{
8+
private const string AccentDark1Key = "SystemAccentColorDark1";
9+
private const string AccentDark2Key = "SystemAccentColorDark2";
10+
private const string AccentDark3Key = "SystemAccentColorDark3";
11+
private const string AccentLight1Key = "SystemAccentColorLight1";
12+
private const string AccentLight2Key = "SystemAccentColorLight2";
13+
private const string AccentLight3Key = "SystemAccentColorLight3";
14+
15+
private readonly UISettings _uiSettings = new();
16+
17+
public AccentColorResource()
18+
{
19+
if (!Application.Current.Resources.ContainsKey(AccentDark1Key))
20+
{
21+
UpdateSystemAccentColors(_uiSettings);
22+
_uiSettings.ColorValuesChanged += OnColorValuesChanged;
23+
}
24+
}
25+
26+
~AccentColorResource()
27+
{
28+
_uiSettings.ColorValuesChanged -= OnColorValuesChanged;
29+
}
30+
31+
public void UpdateSystemAccentColors(UISettings sender)
32+
{
33+
this[AccentDark1Key] = sender.GetColorValue(UIColorType.AccentDark1);
34+
this[AccentDark2Key] = sender.GetColorValue(UIColorType.AccentDark2);
35+
this[AccentDark3Key] = sender.GetColorValue(UIColorType.AccentDark3);
36+
this[AccentLight1Key] = sender.GetColorValue(UIColorType.AccentLight1);
37+
this[AccentLight2Key] = sender.GetColorValue(UIColorType.AccentLight2);
38+
this[AccentLight3Key] = sender.GetColorValue(UIColorType.AccentLight3);
39+
}
40+
41+
private async void OnColorValuesChanged(UISettings sender, object args)
42+
{
43+
await Dispatcher.ResumeForegroundAsync();
44+
UpdateSystemAccentColors(sender);
45+
}
46+
}
47+
}

CoreAppUAP/Common/WeakEvent.cs

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
7+
namespace CoreAppUAP.Common
8+
{
9+
public partial class WeakEvent<TEventArgs> : IList<Action<TEventArgs>>
10+
{
11+
private class Method(Action<TEventArgs> callback) : IEquatable<Method>, IEquatable<Action<TEventArgs>>
12+
{
13+
private readonly bool _isStatic = callback.Target == null;
14+
private readonly WeakReference _reference = new(callback.Target);
15+
private readonly MethodInfo _method = callback.GetMethodInfo();
16+
17+
public bool IsDead => !(_isStatic || _reference.IsAlive);
18+
19+
public void Invoke(TEventArgs arg)
20+
{
21+
if (!IsDead)
22+
{
23+
_method.Invoke(_reference.Target, [arg]);
24+
}
25+
}
26+
27+
public bool Equals(Method other) =>
28+
other != null
29+
&& _reference.Target == other._reference.Target
30+
&& _method == other._method;
31+
32+
public bool Equals(Action<TEventArgs> callback) =>
33+
callback != null
34+
&& _reference.Target == callback.Target
35+
&& _method == callback.GetMethodInfo();
36+
37+
public override bool Equals(object obj) => obj switch
38+
{
39+
Method other => Equals(other),
40+
Action<TEventArgs> callback => Equals(callback),
41+
_ => false,
42+
};
43+
44+
public override int GetHashCode() => (_reference, _method).GetHashCode();
45+
46+
public static implicit operator Method(Action<TEventArgs> callback) => new(callback);
47+
48+
public static explicit operator Action<TEventArgs>(Method method) => method.IsDead ? null : method._method.CreateDelegate(typeof(Action<TEventArgs>), method._reference.Target) as Action<TEventArgs>;
49+
}
50+
51+
private readonly List<Method> _list;
52+
53+
public WeakEvent() => _list = [];
54+
55+
public WeakEvent(IEnumerable<Action<TEventArgs>> collection) => _list = [.. collection.Select<Action<TEventArgs>, Method>(x => x)];
56+
57+
public WeakEvent(int capacity) => _list = new List<Method>(capacity);
58+
59+
public WeakEvent(ReadOnlySpan<Action<TEventArgs>> callbacks) => _list = [.. callbacks];
60+
61+
public int Count => _list.Count;
62+
63+
public bool IsReadOnly => ((ICollection<Method>)_list).IsReadOnly;
64+
65+
public Action<TEventArgs> this[int index]
66+
{
67+
get => (Action<TEventArgs>)_list[index];
68+
set => _list[index] = value;
69+
}
70+
71+
public void Invoke(TEventArgs arg)
72+
{
73+
for (int i = _list.Count; --i >= 0;)
74+
{
75+
if (_list[i].IsDead)
76+
{
77+
_list.RemoveAt(i);
78+
}
79+
else
80+
{
81+
_list[i].Invoke(arg);
82+
}
83+
}
84+
}
85+
86+
public void Add(Action<TEventArgs> callback) => _list.Add(callback);
87+
88+
public void AddRange(IEnumerable<Action<TEventArgs>> collection) => _list.AddRange(collection.Select<Action<TEventArgs>, Method>(x => x));
89+
90+
public void Insert(int index, Action<TEventArgs> item) => _list.Insert(index, item);
91+
92+
public void CopyTo(Action<TEventArgs>[] array, int arrayIndex) => Array.Copy(_list.Select(x => (Action<TEventArgs>)x).ToArray(), 0, array, arrayIndex, _list.Count);
93+
94+
public void Remove(Action<TEventArgs> callback)
95+
{
96+
for (int i = _list.Count; --i >= 0;)
97+
{
98+
if (_list[i].IsDead)
99+
{
100+
_list.RemoveAt(i);
101+
}
102+
else if (_list[i].Equals(callback))
103+
{
104+
_list.RemoveAt(i);
105+
}
106+
}
107+
}
108+
109+
bool ICollection<Action<TEventArgs>>.Remove(Action<TEventArgs> callback)
110+
{
111+
for (int i = _list.Count; --i >= 0;)
112+
{
113+
if (_list[i].IsDead)
114+
{
115+
_list.RemoveAt(i);
116+
}
117+
else if (_list[i].Equals(callback))
118+
{
119+
_list.RemoveAt(i);
120+
return true;
121+
}
122+
}
123+
return false;
124+
}
125+
126+
public void RemoveAt(int index) => _list.RemoveAt(index);
127+
128+
public int RemoveAll(Predicate<Action<TEventArgs>> predicate) => _list.RemoveAll(x => predicate((Action<TEventArgs>)x));
129+
130+
public void Clear() => _list.Clear();
131+
132+
public bool Contains(Action<TEventArgs> callback)
133+
{
134+
for (int i = _list.Count; --i >= 0;)
135+
{
136+
if (_list[i].IsDead)
137+
{
138+
_list.RemoveAt(i);
139+
}
140+
else if (_list[i].Equals(callback))
141+
{
142+
return true;
143+
}
144+
}
145+
return false;
146+
}
147+
148+
public int IndexOf(Action<TEventArgs> callback)
149+
{
150+
for (int i = _list.Count; --i >= 0;)
151+
{
152+
if (_list[i].IsDead)
153+
{
154+
_list.RemoveAt(i);
155+
}
156+
else if (_list[i].Equals(callback))
157+
{
158+
return i;
159+
}
160+
}
161+
return -1;
162+
}
163+
164+
public IEnumerator<Action<TEventArgs>> GetEnumerator() => _list.Select(x => (Action<TEventArgs>)x).GetEnumerator();
165+
166+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
167+
168+
public static WeakEvent<TEventArgs> operator +(WeakEvent<TEventArgs> weakEvent, Action<TEventArgs> callback)
169+
{
170+
weakEvent.Add(callback);
171+
return weakEvent;
172+
}
173+
174+
public static WeakEvent<TEventArgs> operator -(WeakEvent<TEventArgs> weakEvent, Action<TEventArgs> callback)
175+
{
176+
weakEvent.Remove(callback);
177+
return weakEvent;
178+
}
179+
}
180+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.ComponentModel;
2+
using Windows.UI.Xaml;
3+
4+
namespace CoreAppUAP.Controls
5+
{
6+
public partial class SettingsGroup
7+
{
8+
#region Header
9+
10+
/// <summary>
11+
/// Identifies the <see cref="Header"/> dependency property.
12+
/// </summary>
13+
public static readonly DependencyProperty HeaderProperty =
14+
DependencyProperty.Register(
15+
nameof(Header),
16+
typeof(object),
17+
typeof(SettingsGroup),
18+
new PropertyMetadata(null, OnHeaderPropertyChanged));
19+
20+
/// <summary>
21+
/// Gets or sets the Header.
22+
/// </summary>
23+
[Localizable(true)]
24+
public object Header
25+
{
26+
get => GetValue(HeaderProperty);
27+
set => SetValue(HeaderProperty, value);
28+
}
29+
30+
private static void OnHeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
31+
{
32+
if (e.NewValue != e.OldValue)
33+
{
34+
((SettingsGroup)d).OnHeaderChanged();
35+
}
36+
}
37+
38+
#endregion
39+
}
40+
}

0 commit comments

Comments
 (0)