清理ColorPicker,进度条。修复UI问题

This commit is contained in:
2026-02-23 16:49:34 +08:00
parent 1d939d52ed
commit 18174b404c
29 changed files with 1028 additions and 576 deletions

View File

@@ -229,6 +229,8 @@ public class ColorPanel : Control
{
SelectPresetColorCommand = new RelayCommand(ExecuteSelectPresetColor);
Loaded += OnPanelLoaded;
// 拦截面板内所有未处理的左键点击事件防止穿透给其他控件如DataGrid导致焦点切换问题
this.MouseLeftButtonDown += (s, e) => e.Handled = true;
}
/// <summary>
@@ -317,8 +319,15 @@ public class ColorPanel : Control
Debug.Assert(colorCanvas != null, nameof(colorCanvas) + " != null");
if (colorCanvas == null) return;
colorCanvas.CaptureMouse();
// 先解绑再绑定,防止重复点击时引发的多次订阅问题
colorCanvas.MouseMove -= ColorCanvas_MouseMove;
colorCanvas.MouseUp -= ColorCanvas_MouseUp;
colorCanvas.MouseMove += ColorCanvas_MouseMove;
colorCanvas.MouseUp += ColorCanvas_MouseUp;
// 标记事件为已处理,防止冒泡触发 DataGrid 的焦点切换
//e.Handled = true;
}
private void ColorCanvas_MouseUp(object sender, MouseButtonEventArgs e)
@@ -329,6 +338,7 @@ public class ColorPanel : Control
colorCanvas.ReleaseMouseCapture();
colorCanvas.MouseMove -= ColorCanvas_MouseMove;
colorCanvas.MouseUp -= ColorCanvas_MouseUp;
//e.Handled = true;
}
private void ColorCanvas_MouseMove(object sender, MouseEventArgs e)

View File

@@ -23,6 +23,7 @@
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<ContentPresenter
x:Name="ContentHost"
Grid.Column="0"
Margin="4,0,0,0"
HorizontalAlignment="Left"
@@ -64,12 +65,15 @@
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -108,6 +112,7 @@
</controls:IconElement.RenderTransform>
</controls:IconElement>
<ContentPresenter
x:Name="ContentHost"
Grid.Column="0"
Margin="4,0,0,0"
HorizontalAlignment="Left"
@@ -135,12 +140,15 @@
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -179,6 +187,7 @@
</controls:IconElement>
<ContentPresenter
x:Name="ContentHost"
Grid.Row="1"
Margin="0,4,0,0"
HorizontalAlignment="Center"
@@ -210,12 +219,15 @@
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -254,6 +266,7 @@
</controls:IconElement>
<ContentPresenter
x:Name="ContentHost"
Grid.Row="1"
Margin="0,4,0,0"
HorizontalAlignment="Center"
@@ -285,12 +298,15 @@
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryHoverBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource PrimaryPressedBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter TargetName="ContentHost" Property="TextElement.Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -298,7 +314,7 @@
</Setter>
</Style>
<Style TargetType="{x:Type Expander}">
<Style x:Key="FlashExpanderStyle" TargetType="{x:Type Expander}">
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
@@ -383,4 +399,251 @@
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Expander}">
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="FontSize" Value="14" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="4" />
<Setter Property="Padding" Value="4" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<ControlTemplate.Resources>
<!-- 缓动函数 -->
<CubicEase x:Key="EaseInOut" EasingMode="EaseInOut" />
<!-- 上下展开动画 (控制 ScaleY) -->
<Storyboard x:Key="ExpandDownUp">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"
From="0"
To="1"
Duration="0:0:0.25" />
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="Opacity"
From="0"
To="1"
Duration="0:0:0.25" />
</Storyboard>
<!-- 上下折叠动画 -->
<Storyboard x:Key="CollapseDownUp">
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"
From="1"
To="0"
Duration="0:0:0.25" />
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="Opacity"
From="1"
To="0"
Duration="0:0:0.25" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
<DiscreteObjectKeyFrame KeyTime="0:0:0.25" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
<!-- 左右展开动画 (控制 ScaleX) -->
<Storyboard x:Key="ExpandLeftRight">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleX)"
From="0"
To="1"
Duration="0:0:0.25" />
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="Opacity"
From="0"
To="1"
Duration="0:0:0.25" />
</Storyboard>
<!-- 左右折叠动画 -->
<Storyboard x:Key="CollapseLeftRight">
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleX)"
From="1"
To="0"
Duration="0:0:0.25" />
<DoubleAnimation
EasingFunction="{StaticResource EaseInOut}"
Storyboard.TargetName="ExpandSite"
Storyboard.TargetProperty="Opacity"
From="1"
To="0"
Duration="0:0:0.25" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" />
<DiscreteObjectKeyFrame KeyTime="0:0:0.25" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
SnapsToDevicePixels="True">
<DockPanel>
<ToggleButton
x:Name="HeaderSite"
Padding="6"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
DockPanel.Dock="Top"
FocusVisualStyle="{DynamicResource FocusVisual}"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontStretch="{TemplateBinding FontStretch}"
FontStyle="{TemplateBinding FontStyle}"
FontWeight="{TemplateBinding FontWeight}"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ExpanderDownHeaderStyle}" />
<!-- 展开内容区,初始默认为隐藏、透明,且携带 Transform 基底 -->
<ContentPresenter
x:Name="ExpandSite"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
DockPanel.Dock="Bottom"
Focusable="False"
Opacity="0"
Visibility="Collapsed">
<ContentPresenter.LayoutTransform>
<!-- 不再写 x:Name="ExpandScale",提供默认的比例 1,1 供动画去修改 -->
<ScaleTransform ScaleX="1" ScaleY="1" />
</ContentPresenter.LayoutTransform>
</ContentPresenter>
</DockPanel>
</Border>
<ControlTemplate.Triggers>
<!-- 1. 基础布局及方向设置 (仅调整布局结构,不再去控制 Scale) -->
<Trigger Property="ExpandDirection" Value="Right">
<Setter TargetName="ExpandSite" Property="DockPanel.Dock" Value="Right" />
<Setter TargetName="HeaderSite" Property="DockPanel.Dock" Value="Left" />
<Setter TargetName="HeaderSite" Property="Style" Value="{StaticResource ExpanderRightHeaderStyle}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Trigger>
<Trigger Property="ExpandDirection" Value="Up">
<Setter TargetName="ExpandSite" Property="DockPanel.Dock" Value="Top" />
<Setter TargetName="HeaderSite" Property="DockPanel.Dock" Value="Bottom" />
<Setter TargetName="HeaderSite" Property="Style" Value="{StaticResource ExpanderUpHeaderStyle}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Bottom" />
</Trigger>
<Trigger Property="ExpandDirection" Value="Left">
<Setter TargetName="ExpandSite" Property="DockPanel.Dock" Value="Left" />
<Setter TargetName="HeaderSite" Property="DockPanel.Dock" Value="Right" />
<Setter TargetName="HeaderSite" Property="Style" Value="{StaticResource ExpanderLeftHeaderStyle}" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Trigger>
<!-- 2. 为四个方向绑定动画,依靠 Storyboard 中的 From="0" To="1" 实现丝滑展开 -->
<!-- Down -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ExpandDirection" Value="Down" />
<Condition Property="IsExpanded" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
<Setter TargetName="ExpandSite" Property="Opacity" Value="1" />
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandDownUp}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseDownUp}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
<!-- Up -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ExpandDirection" Value="Up" />
<Condition Property="IsExpanded" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
<Setter TargetName="ExpandSite" Property="Opacity" Value="1" />
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandDownUp}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseDownUp}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
<!-- Left -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ExpandDirection" Value="Left" />
<Condition Property="IsExpanded" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
<Setter TargetName="ExpandSite" Property="Opacity" Value="1" />
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandLeftRight}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseLeftRight}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
<!-- Right -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ExpandDirection" Value="Right" />
<Condition Property="IsExpanded" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
<Setter TargetName="ExpandSite" Property="Opacity" Value="1" />
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandLeftRight}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseLeftRight}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -13,8 +13,8 @@ namespace Melskin.Controls
/// </summary>
public class SearchableComboBox : ComboBox
{
private TextBox _editableTextBox;
private bool _isInternalOperation;
private TextBox editableTextBox;
private bool isInternalOperation;
static SearchableComboBox()
{
@@ -41,30 +41,30 @@ namespace Melskin.Controls
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
if (_isInternalOperation) return;
if (isInternalOperation) return;
_isInternalOperation = true;
isInternalOperation = true;
base.OnSelectionChanged(e);
// 重点 1选中项改变后必须彻底清空过滤器否则下次打开下拉框只剩下一项
this.Items.Filter = null;
_isInternalOperation = false;
isInternalOperation = false;
}
private void OnEditableTextBoxTextChanged(object sender, TextChangedEventArgs e)
{
if (_isInternalOperation) return;
if (isInternalOperation) return;
string searchText = _editableTextBox.Text;
string searchText = editableTextBox.Text;
string selectedText = GetItemDisplayText(SelectedItem);
// 重点 2断开锁定逻辑
// 如果文本框的内容和当前选中项的文本不一致,说明用户正在打字替换内容
if (SelectedItem != null && searchText != selectedText)
{
_isInternalOperation = true;
isInternalOperation = true;
SelectedItem = null; // 必须将 SelectedItem 设为 null否则 WPF 会强行还原文本
_isInternalOperation = false;
isInternalOperation = false;
}
// 重点 3执行过滤
@@ -79,7 +79,7 @@ namespace Melskin.Controls
};
// 自动打开下拉框
if (!IsDropDownOpen && _editableTextBox.IsFocused && !string.IsNullOrEmpty(searchText))
if (!IsDropDownOpen && editableTextBox.IsFocused && !string.IsNullOrEmpty(searchText))
{
IsDropDownOpen = true;
}