add:主题切换
This commit is contained in:
@@ -237,7 +237,6 @@
|
||||
<ResourceDictionary Source="Resources/SeewoImageDictionary.xaml"/>
|
||||
<ResourceDictionary Source="Resources/DrawShapeImageDictionary.xaml"/>
|
||||
<ResourceDictionary Source="Resources/IconImageDictionary.xaml"/>
|
||||
<ResourceDictionary Source="Resources/Styles/Light.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
+158
-144
File diff suppressed because it is too large
Load Diff
@@ -457,8 +457,30 @@ namespace Ink_Canvas
|
||||
// HasNewUpdateWindow hasNewUpdateWindow = new HasNewUpdateWindow();
|
||||
if (Environment.Is64BitProcess) GroupBoxInkRecognition.Visibility = Visibility.Collapsed;
|
||||
|
||||
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
|
||||
SystemEvents_UserPreferenceChanged(null, null);
|
||||
// 根据设置应用主题
|
||||
switch (Settings.Appearance.Theme)
|
||||
{
|
||||
case 0: // 浅色主题
|
||||
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
|
||||
SetTheme("Light");
|
||||
break;
|
||||
case 1: // 深色主题
|
||||
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
|
||||
SetTheme("Dark");
|
||||
break;
|
||||
case 2: // 跟随系统
|
||||
if (IsSystemThemeLight())
|
||||
{
|
||||
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
|
||||
SetTheme("Light");
|
||||
}
|
||||
else
|
||||
{
|
||||
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
|
||||
SetTheme("Dark");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//TextBlockVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
LogHelper.WriteLogToFile("Ink Canvas Loaded", LogHelper.LogType.Event);
|
||||
@@ -2741,5 +2763,123 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Theme Toggle
|
||||
|
||||
/// <summary>
|
||||
/// 主题下拉框选择变化事件
|
||||
/// </summary>
|
||||
private void ComboBoxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
|
||||
try
|
||||
{
|
||||
System.Windows.Controls.ComboBox comboBox = sender as System.Windows.Controls.ComboBox;
|
||||
if (comboBox != null)
|
||||
{
|
||||
Settings.Appearance.Theme = comboBox.SelectedIndex;
|
||||
|
||||
// 应用新主题
|
||||
ApplyTheme(comboBox.SelectedIndex);
|
||||
|
||||
// 保存设置
|
||||
SaveSettingsToFile();
|
||||
|
||||
// 显示通知
|
||||
string themeName;
|
||||
switch (comboBox.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
themeName = "浅色主题";
|
||||
break;
|
||||
case 1:
|
||||
themeName = "深色主题";
|
||||
break;
|
||||
case 2:
|
||||
themeName = "跟随系统";
|
||||
break;
|
||||
default:
|
||||
themeName = "未知主题";
|
||||
break;
|
||||
}
|
||||
|
||||
ShowNotification($"已切换到{themeName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"切换主题时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
ShowNotification("主题切换失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用指定主题
|
||||
/// </summary>
|
||||
/// <param name="themeIndex">主题索引:0-浅色,1-深色,2-跟随系统</param>
|
||||
private void ApplyTheme(int themeIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (themeIndex)
|
||||
{
|
||||
case 0: // 浅色主题
|
||||
SetTheme("Light");
|
||||
// 浅色主题下设置浮动栏为完全不透明
|
||||
ViewboxFloatingBar.Opacity = 1.0;
|
||||
break;
|
||||
case 1: // 深色主题
|
||||
SetTheme("Dark");
|
||||
// 深色主题下设置浮动栏为完全不透明
|
||||
ViewboxFloatingBar.Opacity = 1.0;
|
||||
break;
|
||||
case 2: // 跟随系统
|
||||
if (IsSystemThemeLight())
|
||||
{
|
||||
SetTheme("Light");
|
||||
ViewboxFloatingBar.Opacity = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTheme("Dark");
|
||||
ViewboxFloatingBar.Opacity = 1.0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 强制刷新通知框的颜色资源
|
||||
RefreshNotificationColors();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新通知框的颜色资源
|
||||
/// </summary>
|
||||
private void RefreshNotificationColors()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 强制刷新通知框的背景和前景色
|
||||
var border = GridNotifications.Children.OfType<Border>().FirstOrDefault();
|
||||
if (border != null)
|
||||
{
|
||||
border.Background = (Brush)Application.Current.FindResource("SettingsPageBackground");
|
||||
border.BorderBrush = new SolidColorBrush(Color.FromRgb(185, 28, 28)); // 保持红色边框
|
||||
}
|
||||
|
||||
TextBlockNotice.Foreground = (Brush)Application.Current.FindResource("SettingsPageForeground");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"刷新通知框颜色时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,92 @@
|
||||
using iNKORE.UI.WPF.Modern;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Application = System.Windows.Application;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private Color FloatBarForegroundColor = Color.FromRgb(102, 102, 102);
|
||||
private Color FloatBarForegroundColor;
|
||||
|
||||
private void SetTheme(string theme)
|
||||
{
|
||||
// 清理现有的主题资源
|
||||
var resourcesToRemove = new List<ResourceDictionary>();
|
||||
foreach (var dict in Application.Current.Resources.MergedDictionaries)
|
||||
{
|
||||
if (dict.Source != null &&
|
||||
(dict.Source.ToString().Contains("Light.xaml") ||
|
||||
dict.Source.ToString().Contains("Dark.xaml")))
|
||||
{
|
||||
resourcesToRemove.Add(dict);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var dict in resourcesToRemove)
|
||||
{
|
||||
Application.Current.Resources.MergedDictionaries.Remove(dict);
|
||||
}
|
||||
|
||||
// 先添加其他资源
|
||||
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);
|
||||
|
||||
if (theme == "Light")
|
||||
{
|
||||
var rd1 = new ResourceDictionary
|
||||
{ Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative) };
|
||||
Application.Current.Resources.MergedDictionaries.Add(rd1);
|
||||
|
||||
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);
|
||||
|
||||
FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor");
|
||||
InitializeFloatBarForegroundColor();
|
||||
|
||||
// 强制刷新UI
|
||||
window.InvalidateVisual();
|
||||
}
|
||||
else if (theme == "Dark")
|
||||
{
|
||||
var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) };
|
||||
Application.Current.Resources.MergedDictionaries.Add(rd1);
|
||||
|
||||
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();
|
||||
|
||||
// 强制刷新UI
|
||||
window.InvalidateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化FloatBarForegroundColor,从当前主题资源中加载颜色
|
||||
/// </summary>
|
||||
private void InitializeFloatBarForegroundColor()
|
||||
{
|
||||
try
|
||||
{
|
||||
FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 如果无法从资源中加载,使用默认颜色
|
||||
FloatBarForegroundColor = Color.FromRgb(0, 0, 0);
|
||||
LogHelper.WriteLogToFile($"初始化FloatBarForegroundColor时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||
|
||||
@@ -404,17 +404,17 @@ namespace Ink_Canvas
|
||||
{
|
||||
if (mode != "clear")
|
||||
{
|
||||
CursorIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
|
||||
CursorIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
||||
CursorIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedCursorIcon);
|
||||
PenIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
|
||||
PenIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
||||
PenIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedPenIcon);
|
||||
StrokeEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
|
||||
StrokeEraserIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
||||
StrokeEraserIconGeometry.Geometry =
|
||||
Geometry.Parse(XamlGraphicsIconGeometries.LinedEraserStrokeIcon);
|
||||
CircleEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
|
||||
CircleEraserIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
||||
CircleEraserIconGeometry.Geometry =
|
||||
Geometry.Parse(XamlGraphicsIconGeometries.LinedEraserCircleIcon);
|
||||
LassoSelectIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
|
||||
LassoSelectIconGeometry.Brush = new SolidColorBrush(FloatBarForegroundColor);
|
||||
LassoSelectIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedLassoSelectIcon);
|
||||
|
||||
BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245));
|
||||
|
||||
@@ -245,6 +245,9 @@ namespace Ink_Canvas
|
||||
break;
|
||||
}
|
||||
|
||||
// 设置主题下拉框
|
||||
ComboBoxTheme.SelectedIndex = Settings.Appearance.Theme;
|
||||
|
||||
ComboBoxChickenSoupSource.SelectedIndex = Settings.Appearance.ChickenSoupSource;
|
||||
|
||||
ToggleSwitchEnableQuickPanel.IsOn = Settings.Appearance.IsShowQuickPanel;
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="FloatBarBackground" Color="Black" Opacity="0.5"/>
|
||||
<SolidColorBrush x:Key="FloatBarBorderBrush" Color="White" Opacity="0.5"/>
|
||||
<SolidColorBrush x:Key="FloatBarForeground" Color="White"/>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="FloatBarBackground" Opacity="0.6" Color="Black" />
|
||||
<SolidColorBrush x:Key="FloatBarBackgroundWithoutOpacity" Opacity="0.95" Color="Black" />
|
||||
<SolidColorBrush x:Key="FloatBarTitleBackground" Opacity="0.5" Color="#2156c9" />
|
||||
<SolidColorBrush x:Key="FloatBarBorderBrush" Opacity="0.6" Color="White" />
|
||||
<SolidColorBrush x:Key="FloatBarForeground" Color="White" />
|
||||
<Color x:Key="FloatBarForegroundColor">#FFcccccc</Color>
|
||||
|
||||
<SolidColorBrush x:Key="SettingsPageForeground" Color="White" />
|
||||
<SolidColorBrush x:Key="SettingsPageAnnotationForeground" Opacity="0.7" Color="White" />
|
||||
<SolidColorBrush x:Key="SettingsPageBorderBrush" Opacity="0.8" Color="White" />
|
||||
<SolidColorBrush x:Key="SettingsPageBackground" Opacity="0.95" Color="#1f1f1f" />
|
||||
|
||||
<SolidColorBrush x:Key="IconForeground" Color="White" />
|
||||
<SolidColorBrush x:Key="TextForeground" Color="White" />
|
||||
|
||||
<SolidColorBrush x:Key="RedBrush" Color="IndianRed" />
|
||||
<SolidColorBrush x:Key="PurpleBrush" Color="MediumPurple" />
|
||||
|
||||
<Color x:Key="FloatBarButtonBackgroundKey">Transparent</Color>
|
||||
<Color x:Key="FloatBarButtonBackgroundPointerOverKey">#2200CDCD</Color>
|
||||
<Color x:Key="FloatBarButtonButtonBackgroundPressedKey">#4400CDCD</Color>
|
||||
</ResourceDictionary>
|
||||
@@ -1,7 +1,23 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="FloatBarBackground" Color="#fafafa" Opacity="0.95"/>
|
||||
<SolidColorBrush x:Key="FloatBarBorderBrush" Color="#52525b" Opacity="0.6"/>
|
||||
<SolidColorBrush x:Key="FloatBarForeground" Color="#18181b"/>
|
||||
<Color x:Key="FloatBarForegroundColor">#18181b</Color>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="FloatBarBackground" Opacity="1.0" Color="White" />
|
||||
<SolidColorBrush x:Key="FloatBarBackgroundWithoutOpacity" Opacity="1.0" Color="White" />
|
||||
<SolidColorBrush x:Key="FloatBarTitleBackground" Opacity="0.25" Color="#588bfc" />
|
||||
<SolidColorBrush x:Key="FloatBarBorderBrush" Opacity="0.8" Color="Black" />
|
||||
<SolidColorBrush x:Key="FloatBarForeground" Color="Black" />
|
||||
<Color x:Key="FloatBarForegroundColor">#FF000000</Color>
|
||||
|
||||
<SolidColorBrush x:Key="SettingsPageForeground" Color="Black" />
|
||||
<SolidColorBrush x:Key="SettingsPageAnnotationForeground" Color="#666666" />
|
||||
<SolidColorBrush x:Key="SettingsPageBorderBrush" Opacity="0.8" Color="Black" />
|
||||
<SolidColorBrush x:Key="SettingsPageBackground" Opacity="0.95" Color="White" />
|
||||
|
||||
<SolidColorBrush x:Key="IconForeground" Color="#18181b" />
|
||||
<SolidColorBrush x:Key="TextForeground" Color="Black" />
|
||||
|
||||
<SolidColorBrush x:Key="RedBrush" Color="DarkRed" />
|
||||
<SolidColorBrush x:Key="PurpleBrush" Color="DarkBlue" />
|
||||
|
||||
<Color x:Key="FloatBarButtonBackgroundKey">Transparent</Color>
|
||||
<Color x:Key="FloatBarButtonBackgroundPointerOverKey">#66FFFFFF</Color>
|
||||
<Color x:Key="FloatBarButtonButtonBackgroundPressedKey">#99FFFFFF</Color>
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user