Update MW_AutoTheme.cs
This commit is contained in:
@@ -14,19 +14,18 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
/// <summary>
|
private const string ThemeLight = "Light";
|
||||||
/// 浮动栏前景色,根据当前主题动态更新。
|
private const string ThemeDark = "Dark";
|
||||||
/// </summary>
|
private const string LightThemePath = "Resources/Styles/Light.xaml";
|
||||||
|
private const string DarkThemePath = "Resources/Styles/Dark.xaml";
|
||||||
|
private const string DrawShapeImagePath = "Resources/DrawShapeImageDictionary.xaml";
|
||||||
|
private const string SeewoImagePath = "Resources/SeewoImageDictionary.xaml";
|
||||||
|
private const string IconImagePath = "Resources/IconImageDictionary.xaml";
|
||||||
|
|
||||||
private Color FloatBarForegroundColor;
|
private Color FloatBarForegroundColor;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 应用并切换到指定的主题("Light" 或 "Dark"),更新主题资源并刷新相关 UI 元素以反映主题变化。
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="theme">主题标识,支持 "Light" 或 "Dark"(区分大小写)。</param>
|
|
||||||
/// <param name="autoSwitchIcon">若为 true,则根据主题自动切换并保存浮动工具栏的图标设置。</param>
|
|
||||||
private void SetTheme(string theme, bool autoSwitchIcon = false)
|
private void SetTheme(string theme, bool autoSwitchIcon = false)
|
||||||
{
|
{
|
||||||
// 清理现有的主题资源
|
|
||||||
var resourcesToRemove = new List<ResourceDictionary>();
|
var resourcesToRemove = new List<ResourceDictionary>();
|
||||||
foreach (var dict in Application.Current.Resources.MergedDictionaries)
|
foreach (var dict in Application.Current.Resources.MergedDictionaries)
|
||||||
{
|
{
|
||||||
@@ -43,195 +42,85 @@ namespace Ink_Canvas
|
|||||||
Application.Current.Resources.MergedDictionaries.Remove(dict);
|
Application.Current.Resources.MergedDictionaries.Remove(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theme == "Light")
|
var isLightTheme = theme == ThemeLight;
|
||||||
|
var themePath = isLightTheme ? LightThemePath : DarkThemePath;
|
||||||
|
var elementTheme = isLightTheme ? ElementTheme.Light : ElementTheme.Dark;
|
||||||
|
|
||||||
|
var rd1 = new ResourceDictionary { Source = new Uri(themePath, UriKind.Relative) };
|
||||||
|
Application.Current.Resources.MergedDictionaries.Add(rd1);
|
||||||
|
|
||||||
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
// 先加载主题
|
await Task.Delay(100);
|
||||||
var rd1 = new ResourceDictionary
|
Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative)
|
LoadImageResourceDictionary(DrawShapeImagePath);
|
||||||
};
|
LoadImageResourceDictionary(SeewoImagePath);
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd1);
|
LoadImageResourceDictionary(IconImagePath);
|
||||||
|
|
||||||
// 异步加载图形资源,避免阻塞启动
|
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
await Task.Delay(100);
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
var rd2 = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative)
|
|
||||||
};
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd2);
|
|
||||||
|
|
||||||
var rd3 = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative)
|
|
||||||
};
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd3);
|
|
||||||
|
|
||||||
var rd4 = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative)
|
|
||||||
};
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd4);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
ThemeManager.SetRequestedTheme(window, ElementTheme.Light);
|
ThemeManager.SetRequestedTheme(window, elementTheme);
|
||||||
|
|
||||||
InitializeFloatBarForegroundColor();
|
InitializeFloatBarForegroundColor();
|
||||||
|
RefreshQuickPanelIcons();
|
||||||
|
RefreshStrokeSelectionIcons();
|
||||||
|
RefreshImageSelectionIcons();
|
||||||
|
RefreshGestureButtonIcon();
|
||||||
|
RefreshFloatingBarHighlightColors();
|
||||||
|
|
||||||
// 刷新快速面板图标
|
if (autoSwitchIcon)
|
||||||
RefreshQuickPanelIcons();
|
|
||||||
|
|
||||||
// 刷新墨迹选中栏图标
|
|
||||||
RefreshStrokeSelectionIcons();
|
|
||||||
|
|
||||||
// 刷新图片选中栏图标
|
|
||||||
RefreshImageSelectionIcons();
|
|
||||||
|
|
||||||
// 刷新手势按钮图标
|
|
||||||
RefreshGestureButtonIcon();
|
|
||||||
|
|
||||||
RefreshFloatingBarHighlightColors();
|
|
||||||
|
|
||||||
if (autoSwitchIcon)
|
|
||||||
{
|
|
||||||
AutoSwitchFloatingBarIconForTheme("Light");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 强制刷新UI
|
|
||||||
window.InvalidateVisual();
|
|
||||||
|
|
||||||
// 通知其他窗口刷新主题
|
|
||||||
RefreshOtherWindowsTheme();
|
|
||||||
}
|
|
||||||
else if (theme == "Dark")
|
|
||||||
{
|
{
|
||||||
// 先加载主题
|
AutoSwitchFloatingBarIconForTheme(theme);
|
||||||
var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) };
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd1);
|
|
||||||
|
|
||||||
// 异步加载图形资源,避免阻塞启动
|
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
await Task.Delay(100);
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
var rd2 = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative)
|
|
||||||
};
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd2);
|
|
||||||
|
|
||||||
var rd3 = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative)
|
|
||||||
};
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd3);
|
|
||||||
|
|
||||||
var rd4 = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative)
|
|
||||||
};
|
|
||||||
Application.Current.Resources.MergedDictionaries.Add(rd4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
ThemeManager.SetRequestedTheme(window, ElementTheme.Dark);
|
|
||||||
|
|
||||||
InitializeFloatBarForegroundColor();
|
|
||||||
|
|
||||||
// 刷新快速面板图标
|
|
||||||
RefreshQuickPanelIcons();
|
|
||||||
|
|
||||||
// 刷新墨迹选中栏图标
|
|
||||||
RefreshStrokeSelectionIcons();
|
|
||||||
|
|
||||||
// 刷新图片选中栏图标
|
|
||||||
RefreshImageSelectionIcons();
|
|
||||||
|
|
||||||
// 刷新手势按钮图标
|
|
||||||
RefreshGestureButtonIcon();
|
|
||||||
|
|
||||||
RefreshFloatingBarHighlightColors();
|
|
||||||
|
|
||||||
if (autoSwitchIcon)
|
|
||||||
{
|
|
||||||
AutoSwitchFloatingBarIconForTheme("Dark");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 强制刷新UI
|
|
||||||
window.InvalidateVisual();
|
|
||||||
|
|
||||||
// 通知其他窗口刷新主题
|
|
||||||
RefreshOtherWindowsTheme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.InvalidateVisual();
|
||||||
|
RefreshOtherWindowsTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadImageResourceDictionary(string path)
|
||||||
|
{
|
||||||
|
var rd = new ResourceDictionary { Source = new Uri(path, UriKind.Relative) };
|
||||||
|
Application.Current.Resources.MergedDictionaries.Add(rd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 初始化FloatBarForegroundColor,从当前主题资源中加载颜色
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeFloatBarForegroundColor()
|
private void InitializeFloatBarForegroundColor()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor");
|
FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor");
|
||||||
|
|
||||||
// 强制刷新浮动工具栏按钮颜色
|
|
||||||
RefreshFloatingBarButtonColors();
|
RefreshFloatingBarButtonColors();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// 如果无法从资源中加载,使用默认颜色
|
|
||||||
FloatBarForegroundColor = Color.FromRgb(0, 0, 0);
|
FloatBarForegroundColor = Color.FromRgb(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 刷新快速面板图标
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshQuickPanelIcons()
|
private void RefreshQuickPanelIcons()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (LeftUnFoldButtonQuickPanel != null)
|
LeftUnFoldButtonQuickPanel?.InvalidateVisual();
|
||||||
{
|
RightUnFoldButtonQuickPanel?.InvalidateVisual();
|
||||||
LeftUnFoldButtonQuickPanel.InvalidateVisual();
|
LeftSidePanel?.InvalidateVisual();
|
||||||
}
|
RightSidePanel?.InvalidateVisual();
|
||||||
if (RightUnFoldButtonQuickPanel != null)
|
|
||||||
{
|
|
||||||
RightUnFoldButtonQuickPanel.InvalidateVisual();
|
|
||||||
}
|
|
||||||
if (LeftSidePanel != null)
|
|
||||||
{
|
|
||||||
LeftSidePanel.InvalidateVisual();
|
|
||||||
}
|
|
||||||
if (RightSidePanel != null)
|
|
||||||
{
|
|
||||||
RightSidePanel.InvalidateVisual();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 刷新浮动栏高光条颜色
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshFloatingBarHighlightColors()
|
private void RefreshFloatingBarHighlightColors()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (FloatingbarSelectionBG != null && FloatingbarSelectionBG.Visibility == Visibility.Visible)
|
if (FloatingbarSelectionBG != null && FloatingbarSelectionBG.Visibility == Visibility.Visible)
|
||||||
{
|
{
|
||||||
// 根据主题设置高光颜色
|
bool isDarkTheme = IsCurrentThemeDark();
|
||||||
|
|
||||||
Color highlightBackgroundColor;
|
Color highlightBackgroundColor;
|
||||||
Color highlightBarColor;
|
Color highlightBarColor;
|
||||||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
|
|
||||||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
|
|
||||||
|
|
||||||
if (isDarkTheme)
|
if (isDarkTheme)
|
||||||
{
|
{
|
||||||
@@ -244,7 +133,6 @@ namespace Ink_Canvas
|
|||||||
highlightBarColor = Color.FromRgb(37, 99, 235);
|
highlightBarColor = Color.FromRgb(37, 99, 235);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置高光背景颜色
|
|
||||||
FloatingbarSelectionBG.Background = new SolidColorBrush(highlightBackgroundColor);
|
FloatingbarSelectionBG.Background = new SolidColorBrush(highlightBackgroundColor);
|
||||||
if (FloatingbarSelectionBG.Child is System.Windows.Controls.Canvas canvas && canvas.Children.Count > 0)
|
if (FloatingbarSelectionBG.Child is System.Windows.Controls.Canvas canvas && canvas.Children.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -261,74 +149,50 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private bool IsCurrentThemeDark()
|
||||||
/// 刷新浮动工具栏按钮颜色
|
{
|
||||||
/// </summary>
|
return Settings.Appearance.Theme == 1 ||
|
||||||
|
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
|
||||||
|
}
|
||||||
|
|
||||||
private void RefreshFloatingBarButtonColors()
|
private void RefreshFloatingBarButtonColors()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 根据主题选择高光颜色
|
SymbolIconDelete.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DeleteIcon);
|
||||||
Color selectedColor;
|
ShapeDrawFloatingBarBtn.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.ShapesIcon);
|
||||||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
|
SymbolIconUndo.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.UndoIcon);
|
||||||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
|
SymbolIconRedo.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.RedoIcon);
|
||||||
|
CursorWithDelFloatingBarBtn.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.CursorWithDelFloatingBarBtnIcon);
|
||||||
|
WhiteboardFloatingBarBtn.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.WhiteboardFloatingBarBtnIcon);
|
||||||
|
ToolsFloatingBarBtn.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.ToolsFloatingBarBtnIcon);
|
||||||
|
Fold_Icon.Icon.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.FoldIcon);
|
||||||
|
|
||||||
if (isDarkTheme)
|
bool isDarkTheme = IsCurrentThemeDark();
|
||||||
{
|
Color selectedColor = isDarkTheme ? Color.FromRgb(102, 204, 255) : Color.FromRgb(30, 58, 138);
|
||||||
selectedColor = Color.FromRgb(102, 204, 255);
|
|
||||||
}
|
SetAllFloatingBarButtonsToColor(FloatBarForegroundColor);
|
||||||
else
|
|
||||||
{
|
SymbolIconDelete.Icon.Brush = new SolidColorBrush(Color.FromRgb(239, 68, 68));
|
||||||
selectedColor = Color.FromRgb(30, 58, 138);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据当前模式设置按钮颜色
|
|
||||||
switch (_currentToolMode)
|
switch (_currentToolMode)
|
||||||
{
|
{
|
||||||
case "cursor":
|
case "cursor":
|
||||||
Cursor_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
Cursor_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
||||||
Pen_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Eraser_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
SymbolIconSelect.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
break;
|
break;
|
||||||
case "pen":
|
case "pen":
|
||||||
case "color":
|
case "color":
|
||||||
Cursor_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Pen_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
Pen_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
||||||
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Eraser_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
SymbolIconSelect.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
break;
|
break;
|
||||||
case "eraser":
|
case "eraser":
|
||||||
Cursor_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Pen_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Eraser_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
Eraser_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
||||||
SymbolIconSelect.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
break;
|
break;
|
||||||
case "eraserByStrokes":
|
case "eraserByStrokes":
|
||||||
Cursor_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Pen_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(selectedColor);
|
||||||
Eraser_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
SymbolIconSelect.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
break;
|
break;
|
||||||
case "select":
|
case "select":
|
||||||
Cursor_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Pen_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Eraser_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
SymbolIconSelect.Icon.Brush = new SolidColorBrush(selectedColor);
|
SymbolIconSelect.Icon.Brush = new SolidColorBrush(selectedColor);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
// 默认情况,所有按钮都使用主题颜色
|
|
||||||
Cursor_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Pen_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
EraserByStrokes_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
Eraser_Icon.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
SymbolIconSelect.Icon.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -336,79 +200,60 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
void SetAllFloatingBarButtonsToColor(Color color)
|
||||||
/// 处理系统主题偏好变化事件,根据当前设置更新应用主题。
|
{
|
||||||
/// </summary>
|
var brush = new SolidColorBrush(color);
|
||||||
/// <param name="sender">事件发送者。</param>
|
Cursor_Icon.Icon.Brush = brush;
|
||||||
/// <param name="e">用户偏好变化事件参数。</param>
|
Pen_Icon.Icon.Brush = brush;
|
||||||
/// <remarks>
|
EraserByStrokes_Icon.Icon.Brush = brush;
|
||||||
/// 操作包括:
|
Eraser_Icon.Icon.Brush = brush;
|
||||||
/// 1. 根据当前主题设置(Settings.Appearance.Theme)决定使用哪种主题
|
SymbolIconSelect.Icon.Brush = brush;
|
||||||
/// 2. 如果设置为0(浅色主题),则设置为Light主题
|
ShapeDrawFloatingBarBtn.Icon.Brush = brush;
|
||||||
/// 3. 如果设置为1(深色主题),则设置为Dark主题
|
SymbolIconUndo.Icon.Brush = brush;
|
||||||
/// 4. 如果设置为2(跟随系统主题),则根据系统主题设置应用相应的主题
|
SymbolIconRedo.Icon.Brush = brush;
|
||||||
/// </remarks>
|
CursorWithDelFloatingBarBtn.Icon.Brush = brush;
|
||||||
|
WhiteboardFloatingBarBtn.Icon.Brush = brush;
|
||||||
|
ToolsFloatingBarBtn.Icon.Brush = brush;
|
||||||
|
Fold_Icon.Icon.Brush = brush;
|
||||||
|
}
|
||||||
|
|
||||||
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||||
{
|
{
|
||||||
switch (Settings.Appearance.Theme)
|
switch (Settings.Appearance.Theme)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
SetTheme("Light");
|
SetTheme(ThemeLight);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
SetTheme("Dark");
|
SetTheme(ThemeDark);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (IsSystemThemeLight()) SetTheme("Light");
|
SetTheme(IsSystemThemeLight() ? ThemeLight : ThemeDark);
|
||||||
else SetTheme("Dark");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检查系统主题是否为浅色主题。
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>系统主题为浅色返回true,深色返回false。</returns>
|
|
||||||
/// <remarks>
|
|
||||||
/// 操作包括:
|
|
||||||
/// 1. 从注册表中读取系统主题设置
|
|
||||||
/// 2. 检查"SystemUsesLightTheme"键的值
|
|
||||||
/// 3. 如果值为1,则表示系统使用浅色主题
|
|
||||||
/// 4. 捕获可能的异常,确保方法不会因异常而崩溃
|
|
||||||
/// </remarks>
|
|
||||||
private bool IsSystemThemeLight()
|
private bool IsSystemThemeLight()
|
||||||
{
|
{
|
||||||
var light = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var registryKey = Registry.CurrentUser;
|
var registryKey = Registry.CurrentUser;
|
||||||
var themeKey =
|
var themeKey = registryKey.OpenSubKey("software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
|
||||||
registryKey.OpenSubKey("software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
|
if (themeKey != null)
|
||||||
var keyValue = 0;
|
{
|
||||||
if (themeKey != null) keyValue = (int)themeKey.GetValue("SystemUsesLightTheme");
|
int keyValue = (int)themeKey.GetValue("SystemUsesLightTheme");
|
||||||
if (keyValue == 1) light = true;
|
return keyValue == 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
|
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
|
||||||
|
return false;
|
||||||
return light;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根据主题自动切换浮动栏图标
|
|
||||||
/// </summary>
|
|
||||||
private void AutoSwitchFloatingBarIconForTheme(string theme)
|
private void AutoSwitchFloatingBarIconForTheme(string theme)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (theme == "Light")
|
Settings.Appearance.FloatingBarImg = theme == ThemeLight ? 0 : 3;
|
||||||
{
|
|
||||||
Settings.Appearance.FloatingBarImg = 0;
|
|
||||||
}
|
|
||||||
else if (theme == "Dark")
|
|
||||||
{
|
|
||||||
Settings.Appearance.FloatingBarImg = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateFloatingBarIcon();
|
UpdateFloatingBarIcon();
|
||||||
UpdateFloatingBarIconComboBox();
|
UpdateFloatingBarIconComboBox();
|
||||||
}
|
}
|
||||||
@@ -417,9 +262,6 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新设置界面中的浮动栏图标选择下拉框显示
|
|
||||||
/// </summary>
|
|
||||||
private void UpdateFloatingBarIconComboBox()
|
private void UpdateFloatingBarIconComboBox()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -434,94 +276,45 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 刷新墨迹选中栏图标
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshStrokeSelectionIcons()
|
private void RefreshStrokeSelectionIcons()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (BorderStrokeSelectionControl != null)
|
if (BorderStrokeSelectionControl != null)
|
||||||
{
|
{
|
||||||
// 强制刷新墨迹选中栏的视觉状态
|
|
||||||
BorderStrokeSelectionControl.InvalidateVisual();
|
BorderStrokeSelectionControl.InvalidateVisual();
|
||||||
|
|
||||||
// 刷新墨迹选中栏内的所有图标
|
|
||||||
var viewbox = BorderStrokeSelectionControl.Child as Viewbox;
|
var viewbox = BorderStrokeSelectionControl.Child as Viewbox;
|
||||||
if (viewbox?.Child is ui.SimpleStackPanel stackPanel)
|
if (viewbox?.Child is ui.SimpleStackPanel stackPanel)
|
||||||
{
|
{
|
||||||
RefreshStrokeSelectionIconsRecursive(stackPanel);
|
RefreshIconsRecursive(stackPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// 忽略异常,确保主题切换不会因为图标刷新失败而中断
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 递归刷新墨迹选中栏内的图标
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshStrokeSelectionIconsRecursive(System.Windows.Controls.Panel panel)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach (var child in panel.Children)
|
|
||||||
{
|
|
||||||
if (child is Image image)
|
|
||||||
{
|
|
||||||
// 强制刷新图像
|
|
||||||
image.InvalidateVisual();
|
|
||||||
}
|
|
||||||
else if (child is System.Windows.Controls.Panel childPanel)
|
|
||||||
{
|
|
||||||
// 递归处理子面板
|
|
||||||
RefreshStrokeSelectionIconsRecursive(childPanel);
|
|
||||||
}
|
|
||||||
else if (child is Border border && border.Child is System.Windows.Controls.Panel borderPanel)
|
|
||||||
{
|
|
||||||
// 处理Border内的面板
|
|
||||||
RefreshStrokeSelectionIconsRecursive(borderPanel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// 忽略异常
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 刷新图片选中栏图标
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshImageSelectionIcons()
|
private void RefreshImageSelectionIcons()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (BorderImageSelectionControl != null)
|
if (BorderImageSelectionControl != null)
|
||||||
{
|
{
|
||||||
// 强制刷新图片选中栏的视觉状态
|
|
||||||
BorderImageSelectionControl.InvalidateVisual();
|
BorderImageSelectionControl.InvalidateVisual();
|
||||||
|
|
||||||
// 刷新图片选中栏内的所有图标
|
|
||||||
var viewbox = BorderImageSelectionControl.Child as Viewbox;
|
var viewbox = BorderImageSelectionControl.Child as Viewbox;
|
||||||
if (viewbox?.Child is ui.SimpleStackPanel stackPanel)
|
if (viewbox?.Child is ui.SimpleStackPanel stackPanel)
|
||||||
{
|
{
|
||||||
RefreshImageSelectionIconsRecursive(stackPanel);
|
RefreshIconsRecursive(stackPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// 忽略异常,确保主题切换不会因为图标刷新失败而中断
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private void RefreshIconsRecursive(System.Windows.Controls.Panel panel)
|
||||||
/// 递归刷新图片选中栏内的图标
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshImageSelectionIconsRecursive(System.Windows.Controls.Panel panel)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -529,22 +322,18 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
if (child is Image image)
|
if (child is Image image)
|
||||||
{
|
{
|
||||||
// 强制刷新图像
|
|
||||||
image.InvalidateVisual();
|
image.InvalidateVisual();
|
||||||
}
|
}
|
||||||
else if (child is System.Windows.Controls.Panel childPanel)
|
else if (child is System.Windows.Controls.Panel childPanel)
|
||||||
{
|
{
|
||||||
// 递归处理子面板
|
RefreshIconsRecursive(childPanel);
|
||||||
RefreshImageSelectionIconsRecursive(childPanel);
|
|
||||||
}
|
}
|
||||||
else if (child is Border border && border.Child is System.Windows.Controls.Panel borderPanel)
|
else if (child is Border border && border.Child is System.Windows.Controls.Panel borderPanel)
|
||||||
{
|
{
|
||||||
// 处理Border内的面板
|
RefreshIconsRecursive(borderPanel);
|
||||||
RefreshImageSelectionIconsRecursive(borderPanel);
|
|
||||||
}
|
}
|
||||||
else if (child is Grid grid)
|
else if (child is Grid grid)
|
||||||
{
|
{
|
||||||
// 处理Grid内的子元素
|
|
||||||
foreach (var gridChild in grid.Children)
|
foreach (var gridChild in grid.Children)
|
||||||
{
|
{
|
||||||
if (gridChild is Image gridImage)
|
if (gridChild is Image gridImage)
|
||||||
@@ -557,18 +346,13 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// 忽略异常
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 刷新手势按钮图标
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshGestureButtonIcon()
|
private void RefreshGestureButtonIcon()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 调用手势按钮颜色和图标更新方法,该方法会根据当前主题和手势状态设置正确的图标
|
|
||||||
CheckEnableTwoFingerGestureBtnColorPrompt();
|
CheckEnableTwoFingerGestureBtnColorPrompt();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -576,14 +360,10 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 刷新其他窗口的主题
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshOtherWindowsTheme()
|
private void RefreshOtherWindowsTheme()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 刷新所有打开的窗口
|
|
||||||
foreach (Window window in Application.Current.Windows)
|
foreach (Window window in Application.Current.Windows)
|
||||||
{
|
{
|
||||||
if (window is CountdownTimerWindow timerWindow)
|
if (window is CountdownTimerWindow timerWindow)
|
||||||
@@ -600,20 +380,12 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新计时器控件
|
TimerControl?.RefreshTheme();
|
||||||
if (TimerControl != null)
|
MinimizedTimerControl?.RefreshTheme();
|
||||||
{
|
|
||||||
TimerControl.RefreshTheme();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MinimizedTimerControl != null)
|
|
||||||
{
|
|
||||||
MinimizedTimerControl.RefreshTheme();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user