From e5f139264e85d216a5b9485db1afe6745750ed11 Mon Sep 17 00:00:00 2001 From: GG Z <903524121@qq.com> Date: Tue, 26 Aug 2025 21:33:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E8=89=B2=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NeoUI/NeoUI/Appearance/ThemeManager.cs | 64 +++--- NeoUI/NeoUI/Controls/Alert.xaml | 5 +- NeoUI/NeoUI/Controls/Badge.xaml | 173 +------------- NeoUI/NeoUI/Controls/Breadcrumb.xaml | 2 +- NeoUI/NeoUI/Controls/ButtonsStyle.xaml | 4 +- NeoUI/NeoUI/Controls/CalendarStyle.xaml | 2 +- NeoUI/NeoUI/Controls/Card.xaml | 38 +-- NeoUI/NeoUI/Controls/Cascader.xaml | 2 +- NeoUI/NeoUI/Controls/CheckBoxStyle.xaml | 216 +++++++++--------- NeoUI/NeoUI/Controls/CodeBox.xaml | 2 +- .../Controls/ColorPicker/ColorPicker.xaml | 2 +- NeoUI/NeoUI/Controls/ComboBoxStyle.xaml | 4 +- NeoUI/NeoUI/Controls/DataGridStyle.xaml | 5 +- .../Controls/Decorations/EmbossBorder.xaml | 2 +- .../Controls/Decorations/LightedSurface.xaml | 2 +- .../Controls/Decorations/SlotBorder.xaml | 2 +- NeoUI/NeoUI/Controls/ExpanderStyle.xaml | 4 +- NeoUI/NeoUI/Controls/FlattenComboBox.xaml | 4 +- NeoUI/NeoUI/Controls/GroupBoxStyle.xaml | 2 +- NeoUI/NeoUI/Controls/ListBoxStyle.xaml | 105 ++++----- NeoUI/NeoUI/Controls/ListViewStyle.xaml | 111 ++++----- NeoUI/NeoUI/Controls/MultiTreeView.xaml | 6 +- .../Notification/NotificationView.xaml | 2 +- NeoUI/NeoUI/Controls/NumberBox.xaml | 2 +- NeoUI/NeoUI/Controls/PaginationControl.xaml | 2 +- NeoUI/NeoUI/Controls/PasswordBoxStyle.xaml | 2 +- NeoUI/NeoUI/Controls/Pill.xaml | 2 +- NeoUI/NeoUI/Controls/RadioButtonStyle.xaml | 14 +- NeoUI/NeoUI/Controls/ScrollViewerStyle.xaml | 2 +- NeoUI/NeoUI/Controls/SliderStyle.xaml | 2 +- NeoUI/NeoUI/Controls/StatusBarStyle.xaml | 2 +- NeoUI/NeoUI/Controls/TabViewStyle.xaml | 8 +- NeoUI/NeoUI/Controls/TextBoxStyle.xaml | 6 +- NeoUI/NeoUI/Controls/ToggleButtonStyle.xaml | 12 +- NeoUI/NeoUI/Controls/ToolBarStyle.xaml | 8 +- NeoUI/NeoUI/Controls/TreeViewStyle.xaml | 4 +- NeoUI/NeoUI/Controls/UploadArea.xaml | 4 +- NeoUI/NeoUI/Controls/WindowStyle.xaml | 5 +- NeoUI/NeoUI/Themes/Dark.xaml | 29 +-- NeoUI/NeoUI/Themes/Light.xaml | 49 ++-- NeoUI/NeoUITest/App.xaml | 2 +- NeoUI/NeoUITest/MainWindow.xaml | 16 +- .../Assists/KeyIntPtrHelper.cs | 2 +- .../ModelManager/ModelCheckView.xaml | 63 +++-- .../ModelManager/ModelCheckView.xaml.cs | 8 +- .../RvFamily/FamilyProcessorView.xaml | 4 +- ShrlAlgoToolkit.RevitAddins/WPFUI.xaml | 31 +-- 47 files changed, 432 insertions(+), 606 deletions(-) diff --git a/NeoUI/NeoUI/Appearance/ThemeManager.cs b/NeoUI/NeoUI/Appearance/ThemeManager.cs index a16f90e..1cea0bf 100644 --- a/NeoUI/NeoUI/Appearance/ThemeManager.cs +++ b/NeoUI/NeoUI/Appearance/ThemeManager.cs @@ -14,7 +14,6 @@ namespace NeoUI.Appearance /// 3. 动画策略:先交换字典(保证新增键立即可用)再对所有可动画 SolidColorBrush 做颜色补间(含新增键过渡) /// 4. 只允许同时存在一个主题字典 + 一个调色板字典(顺序:主题 -> 调色板 -> 其它) /// 5. 可选持久化 - /// 6. 防重入(_isSwitching) /// 兼容:保留旧 API (ApplyThemeMode / ApplyThemePalette / SwitchThemeMode 等) /// /// 设计要点: @@ -104,13 +103,7 @@ namespace NeoUI.Appearance foreach (var key in AnimatableBrushKeys) { var brush = FindBrushInManagedDictionaries(resources, key); - //if (key == "TextPrimaryBrush") - //{ - // System.Diagnostics.Debug.WriteLine($"--- BAD STATE (Snapshot) ---"); - // System.Diagnostics.Debug.WriteLine($"Brush HashCode: {brush.GetHashCode()}"); - // System.Diagnostics.Debug.WriteLine($"Brush Color: {brush.Color}"); // 这里会显示错误的颜色 - // System.Diagnostics.Debug.WriteLine($"IsFrozen: {brush.IsFrozen}"); // 强烈怀疑这里会是 True - //} + if (brush != null) snapshot[key] = brush.Color; } @@ -346,13 +339,7 @@ namespace NeoUI.Appearance if (!modeChanged && !paletteChanged) return; var appResources = Current.Resources; - //foreach (var d in appResources.MergedDictionaries) - //{ - // foreach (DictionaryEntry item in d) - // { - // Debug.WriteLine($"{item.Key} = {item.Value}"); - // } - //} + Dictionary? fromColors = null; if (animate) { @@ -537,14 +524,29 @@ namespace NeoUI.Appearance private readonly Application? application; private Window? mainWindow; private ResourceDictionary? resources; - + private static bool ApplicationHasResources(Application application) + { + return application + .Resources.MergedDictionaries + .Where(e => e.Source is not null) + .Any(e => e.Source.ToString().Contains(LibraryNamespace)); + } + /// + /// 是否绑定到一个有效的 Application 实例。 + /// + public bool IsApplication => application is not null; private ThemeManager(Application? application) { - //var goodBrush = (SolidColorBrush)Application.Current.Resources["TextPrimaryBrush"]; - //System.Diagnostics.Debug.WriteLine($"--- GOOD STATE ---"); - //System.Diagnostics.Debug.WriteLine($"Brush HashCode: {goodBrush.GetHashCode()}"); - //System.Diagnostics.Debug.WriteLine($"Brush Color: {goodBrush.Color}"); - //System.Diagnostics.Debug.WriteLine($"IsFrozen: {goodBrush.IsFrozen}"); + if (application is null) + { + return; + } + + if (!ApplicationHasResources(application)) + { + return; + } + this.application = application; } @@ -597,17 +599,19 @@ namespace NeoUI.Appearance { get { - if (resources != null) return application?.Resources ?? resources; - - resources = new ResourceDictionary(); - try + if (resources == null) { - var themesDictionary = new ThemesDictionary() { Mode = ActiveThemeMode, Palette = ActiveThemePalette }; - var controlsDictionary = new ControlsDictionary(); - resources.MergedDictionaries.Add(themesDictionary); - resources.MergedDictionaries.Add(controlsDictionary); + resources = new ResourceDictionary(); + try + { + var themesDictionary = new ThemesDictionary() { Mode = ActiveThemeMode, Palette = ActiveThemePalette }; + var controlsDictionary = new ControlsDictionary(); + resources.MergedDictionaries.Add(themesDictionary); + resources.MergedDictionaries.Add(controlsDictionary); + } + catch { /* 忽略初始化异常 */ } } - catch { /* 忽略初始化异常 */ } + return application?.Resources ?? resources; } set diff --git a/NeoUI/NeoUI/Controls/Alert.xaml b/NeoUI/NeoUI/Controls/Alert.xaml index 42a3c62..1f954e2 100644 --- a/NeoUI/NeoUI/Controls/Alert.xaml +++ b/NeoUI/NeoUI/Controls/Alert.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:assists="clr-namespace:NeoUI.Assists" xmlns:controls="clr-namespace:NeoUI.Controls" + xmlns:nvd="clr-namespace:NeoUI.Controls.Decorations" xmlns:conv="clr-namespace:NeoUI.Converters"> @@ -34,7 +35,7 @@ - - + diff --git a/NeoUI/NeoUI/Controls/Badge.xaml b/NeoUI/NeoUI/Controls/Badge.xaml index d387640..fc9fb04 100644 --- a/NeoUI/NeoUI/Controls/Badge.xaml +++ b/NeoUI/NeoUI/Controls/Badge.xaml @@ -2,7 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:controls="clr-namespace:NeoUI.Controls" xmlns:converters="clr-namespace:NeoUI.Converters" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:nvd="clr-namespace:NeoUI.Controls.Decorations"> @@ -34,136 +35,7 @@ To="2.4" /> - - - - - - - - - - - - - - - - - - - - + - - \ No newline at end of file diff --git a/NeoUI/NeoUI/Controls/Breadcrumb.xaml b/NeoUI/NeoUI/Controls/Breadcrumb.xaml index 9dd7ae6..dec5d3d 100644 --- a/NeoUI/NeoUI/Controls/Breadcrumb.xaml +++ b/NeoUI/NeoUI/Controls/Breadcrumb.xaml @@ -6,7 +6,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - - \ No newline at end of file diff --git a/NeoUI/NeoUI/Controls/CodeBox.xaml b/NeoUI/NeoUI/Controls/CodeBox.xaml index 73ed822..190929c 100644 --- a/NeoUI/NeoUI/Controls/CodeBox.xaml +++ b/NeoUI/NeoUI/Controls/CodeBox.xaml @@ -33,7 +33,7 @@ - - - + diff --git a/NeoUI/NeoUI/Controls/ToggleButtonStyle.xaml b/NeoUI/NeoUI/Controls/ToggleButtonStyle.xaml index 95a84a2..01a5cad 100644 --- a/NeoUI/NeoUI/Controls/ToggleButtonStyle.xaml +++ b/NeoUI/NeoUI/Controls/ToggleButtonStyle.xaml @@ -8,9 +8,9 @@ @@ -43,7 +43,7 @@ - + - @@ -87,20 +90,17 @@ - - - - - - - - + Columns="1"> + + + -