fix: 颜色设置跟随内容

master
Tongg 7 months ago
parent 2a2cb1cbce
commit 6980be39f9
  1. 38
      Views/Configuration/SettingPages/ModelColorSetPage.xaml
  2. 102
      Views/Configuration/SettingPages/ModelColorSetPage.xaml.cs
  3. 4
      Views/UserControl/ViewportData/ViewportData.cs

@ -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">
<Border.Resources>
<Style x:Key="BorderRowStyle" TargetType="Border">
@ -29,7 +29,7 @@
<!-- <Setter Property="Padding" Value="0 0 10 0" /> -->
<!-- <Setter Property="Margin" Value="0 5" /> -->
<!-- </Style> -->
</Border.Resources>
<Grid>
<Grid.RowDefinitions>
@ -60,7 +60,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetMainFaceColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="2">
<Grid.ColumnDefinitions>
@ -68,7 +68,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetMainBorderColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding BORDER_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding BORDER_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
</Grid>
</Grid>
@ -99,7 +99,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetSelectedColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding SELECTED_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding SELECTED_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="2" Row="0">
<Grid.ColumnDefinitions>
@ -107,7 +107,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetSelectedBorderColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding SELECTED_BORDER_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding SELECTED_BORDER_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="4" Row="0">
<Grid.ColumnDefinitions>
@ -115,7 +115,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetSelectedTypeColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding SELECTED_TYPE_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding SELECTED_TYPE_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="0" Row="2">
<Grid.ColumnDefinitions>
@ -123,7 +123,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetSelectedTextColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Center" Content="{Binding SELECTED_FONT_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" Height="28" VerticalAlignment="Top" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Center" Content="{Binding SELECTED_FONT_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" Height="28" VerticalAlignment="Top" />
</Grid>
<Grid Grid.Column="2" Row="2">
<Grid.ColumnDefinitions>
@ -131,7 +131,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetSelectedLineColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding RULER_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding RULER_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="4" Row="2">
<Grid.ColumnDefinitions>
@ -139,7 +139,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetSelectedPosdColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding ARROW_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding ARROW_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
</Grid>
</Grid>
@ -172,7 +172,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetErrorColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding BLEMISH_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding BLEMISH_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="2" Row="0">
<Grid.ColumnDefinitions>
@ -180,7 +180,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetTableColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding TABLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding TABLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="4" Row="0">
<Grid.ColumnDefinitions>
@ -188,7 +188,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetUpperColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding UPPER_MAIN_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding UPPER_MAIN_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="0" Row="2">
<Grid.ColumnDefinitions>
@ -196,7 +196,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetStarColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding STAR_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding STAR_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="2" Row="2">
<Grid.ColumnDefinitions>
@ -204,7 +204,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetUpperGirdleColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding UPPER_GIRDLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding UPPER_GIRDLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="4" Row="2">
<Grid.ColumnDefinitions>
@ -212,7 +212,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetGirdleColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding GIRDLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding GIRDLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="0" Row="4">
<Grid.ColumnDefinitions>
@ -220,7 +220,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetPavilionColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding PAVILION_MAIN_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding PAVILION_MAIN_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="2" Row="4">
<Grid.ColumnDefinitions>
@ -228,7 +228,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetLowerGirdleColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding LOWER_GIRDLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding LOWER_GIRDLE_FACET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
<Grid Grid.Column="4" Row="4">
<Grid.ColumnDefinitions>
@ -236,7 +236,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" FontSize="14" Content="{StaticResource SystemSettingModelSetCuletColor}" HorizontalAlignment="Right" Width="150" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" HorizontalAlignment="Left" Content="{Binding CULET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
<Label Grid.Column="1" FontSize="14" Background="#FF000000" local:LabelContentChangedBehavior.EnableContentChanged="True" HorizontalAlignment="Left" Content="{Binding CULET_COLOR}" Width="100" MouseLeftButtonDown="LabelsColor_OnMouseLeftButtonDown" />
</Grid>
</Grid>
</Grid>

@ -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);
}
}
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);
}
}
}

@ -17,8 +17,8 @@ public class ViewportData
/// 钻石数据
/// </summary>
public String DiamondData { get; set; }
public ColorConfigEntity ColorConfig { get; set; }
public ColorConfigEntity ColorConfig { get; set; } = new ColorConfigEntity();
/// <summary>
/// 初始化构造

Loading…
Cancel
Save