diff --git a/Views/Configuration/SettingPages/ModelColorSetPage.xaml b/Views/Configuration/SettingPages/ModelColorSetPage.xaml
index 57034b5..a3955d9 100644
--- a/Views/Configuration/SettingPages/ModelColorSetPage.xaml
+++ b/Views/Configuration/SettingPages/ModelColorSetPage.xaml
@@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SparkClient.Views.Configuration.SettingPages"
xmlns:hc="https://handyorg.github.io/handycontrol"
- mc:Ignorable="d"
+ mc:Ignorable="d" local:LabelContentChangedBehavior.ContentChanged="Label_ContentChanged"
d:DesignHeight="400" d:DesignWidth="1000">
-->
-
+
@@ -60,7 +60,7 @@
-
+
@@ -68,7 +68,7 @@
-
+
@@ -99,7 +99,7 @@
-
+
@@ -107,7 +107,7 @@
-
+
@@ -115,7 +115,7 @@
-
+
@@ -123,7 +123,7 @@
-
+
@@ -131,7 +131,7 @@
-
+
@@ -139,7 +139,7 @@
-
+
@@ -172,7 +172,7 @@
-
+
@@ -180,7 +180,7 @@
-
+
@@ -188,7 +188,7 @@
-
+
@@ -196,7 +196,7 @@
-
+
@@ -204,7 +204,7 @@
-
+
@@ -212,7 +212,7 @@
-
+
@@ -220,7 +220,7 @@
-
+
@@ -228,7 +228,7 @@
-
+
@@ -236,7 +236,7 @@
-
+
diff --git a/Views/Configuration/SettingPages/ModelColorSetPage.xaml.cs b/Views/Configuration/SettingPages/ModelColorSetPage.xaml.cs
index 3ea85a4..33ba06a 100644
--- a/Views/Configuration/SettingPages/ModelColorSetPage.xaml.cs
+++ b/Views/Configuration/SettingPages/ModelColorSetPage.xaml.cs
@@ -1,3 +1,5 @@
+using System.ComponentModel;
+using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
@@ -44,4 +46,102 @@ public partial class ModelColorSetPage
(byte)(255 - originalColor.B));
return new SolidColorBrush(inverseColor);
}
-}
\ No newline at end of file
+
+ private void Label_ContentChanged(object sender, RoutedEventArgs e)
+ {
+ if (e.Source is Label label)
+ {
+ var newContent = label.Content?.ToString();
+ // 在这里处理 Content 变化后的逻辑
+ // 例如:
+ label.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(newContent));
+ label.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(newContent));
+
+ }
+ }
+
+
+}
+
+public static class LabelContentChangedBehavior
+ {
+ public static readonly DependencyProperty EnableContentChangedProperty =
+ DependencyProperty.RegisterAttached(
+ "EnableContentChanged",
+ typeof(bool),
+ typeof(LabelContentChangedBehavior),
+ new PropertyMetadata(false, OnEnableContentChangedChanged));
+
+ // 定义一个附加事件
+ public static readonly RoutedEvent ContentChangedEvent =
+ EventManager.RegisterRoutedEvent(
+ "ContentChanged",
+ RoutingStrategy.Bubble,
+ typeof(RoutedEventHandler),
+ typeof(LabelContentChangedBehavior));
+
+ // 添加和移除事件的附加方法
+ public static void AddContentChangedHandler(DependencyObject d, RoutedEventHandler handler)
+ {
+ if (d is UIElement uiElement)
+ {
+ uiElement.AddHandler(ContentChangedEvent, handler);
+ }
+ }
+
+ public static void RemoveContentChangedHandler(DependencyObject d, RoutedEventHandler handler)
+ {
+ if (d is UIElement uiElement)
+ {
+ uiElement.RemoveHandler(ContentChangedEvent, handler);
+ }
+ }
+
+ public static bool GetEnableContentChanged(DependencyObject obj)
+ {
+ return (bool)obj.GetValue(EnableContentChangedProperty);
+ }
+
+ public static void SetEnableContentChanged(DependencyObject obj, bool value)
+ {
+ obj.SetValue(EnableContentChangedProperty, value);
+ }
+
+ private static void OnEnableContentChangedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is Label label)
+ {
+ if ((bool)e.NewValue)
+ {
+ DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(
+ Label.ContentProperty, typeof(Label));
+
+ if (dpd != null)
+ {
+ dpd.AddValueChanged(label, OnLabelContentChanged);
+ }
+ }
+ else
+ {
+ DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(
+ Label.ContentProperty, typeof(Label));
+
+ if (dpd != null)
+ {
+ dpd.RemoveValueChanged(label, OnLabelContentChanged);
+ }
+ }
+ }
+ }
+
+ private static void OnLabelContentChanged(object sender, EventArgs e)
+ {
+ if (sender is Label label)
+ {
+ var newContent = label.Content?.ToString();
+ // 创建一个新的 RoutedEventArgs,并设置源为当前 Label
+ RoutedEventArgs args = new RoutedEventArgs(ContentChangedEvent, label);
+ label.RaiseEvent(args);
+ }
+ }
+ }
\ No newline at end of file
diff --git a/Views/UserControl/ViewportData/ViewportData.cs b/Views/UserControl/ViewportData/ViewportData.cs
index daf2154..b65d9b1 100644
--- a/Views/UserControl/ViewportData/ViewportData.cs
+++ b/Views/UserControl/ViewportData/ViewportData.cs
@@ -17,8 +17,8 @@ public class ViewportData
/// 钻石数据
///
public String DiamondData { get; set; }
-
- public ColorConfigEntity ColorConfig { get; set; }
+
+ public ColorConfigEntity ColorConfig { get; set; } = new ColorConfigEntity();
///
/// 初始化构造