优化样式和功能
This commit is contained in:
@@ -118,10 +118,13 @@
|
|||||||
<Setter Property="BorderThickness" Value="0" />
|
<Setter Property="BorderThickness" Value="0" />
|
||||||
<Setter Property="assists:ControlAssist.Orientation" Value="Horizontal" />
|
<Setter Property="assists:ControlAssist.Orientation" Value="Horizontal" />
|
||||||
<Setter Property="assists:ControlAssist.CornerRadius" Value="10" />
|
<Setter Property="assists:ControlAssist.CornerRadius" Value="10" />
|
||||||
|
|
||||||
|
<!-- 1. 设置 ItemContainerStyle -->
|
||||||
<Setter Property="ItemContainerStyle">
|
<Setter Property="ItemContainerStyle">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<Style TargetType="{x:Type ListBoxItem}">
|
<Style TargetType="{x:Type ListBoxItem}">
|
||||||
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
|
<Setter Property="Background" Value="Transparent" />
|
||||||
|
<!-- 改为透明,露出父级背景 -->
|
||||||
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
|
||||||
<Setter Property="FontSize" Value="16" />
|
<Setter Property="FontSize" Value="16" />
|
||||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||||
@@ -129,10 +132,11 @@
|
|||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<!-- 注意:这里的 CornerRadius 设为 0,因为圆角由外层 ListBox 统一裁切 -->
|
||||||
<Border
|
<Border
|
||||||
x:Name="Border"
|
x:Name="Border"
|
||||||
Background="{TemplateBinding Background}"
|
Background="{TemplateBinding Background}"
|
||||||
CornerRadius="{Binding Path=(assists:ControlAssist.CornerRadius), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
|
CornerRadius="0"
|
||||||
Cursor="Hand">
|
Cursor="Hand">
|
||||||
<ContentPresenter
|
<ContentPresenter
|
||||||
Margin="10"
|
Margin="10"
|
||||||
@@ -143,8 +147,8 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
<ControlTemplate.Triggers>
|
<ControlTemplate.Triggers>
|
||||||
<Trigger Property="IsSelected" Value="True">
|
<Trigger Property="IsSelected" Value="True">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource TextAccentBrush}" />
|
||||||
<Setter Property="Background" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
|
<Setter Property="Background" Value="{DynamicResource PrimaryNormalBrush}" />
|
||||||
</Trigger>
|
</Trigger>
|
||||||
<Trigger Property="IsEnabled" Value="False">
|
<Trigger Property="IsEnabled" Value="False">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
|
||||||
@@ -156,7 +160,8 @@
|
|||||||
</Style>
|
</Style>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
<!-- 设置布局面板为水平排列 -->
|
|
||||||
|
<!-- 2. 设置布局面板为水平/垂直排列 -->
|
||||||
<Setter Property="ItemsPanel">
|
<Setter Property="ItemsPanel">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ItemsPanelTemplate>
|
<ItemsPanelTemplate>
|
||||||
@@ -164,10 +169,32 @@
|
|||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|
||||||
|
<!-- 3. 设置 ListBox 自身的 Template 进行整体裁切 (核心修改点) -->
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="ListBox">
|
<ControlTemplate TargetType="ListBox">
|
||||||
<ItemsPresenter />
|
<!-- 外层框架:提供整体的背景和真实的圆角 -->
|
||||||
|
<Border
|
||||||
|
Background="{TemplateBinding Background}"
|
||||||
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
|
CornerRadius="{Binding Path=(assists:ControlAssist.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}">
|
||||||
|
<Grid>
|
||||||
|
<!-- 绘制一个带有圆角的黑色遮罩 Border (颜色不重要,OpacityMask只看透明度) -->
|
||||||
|
<Border
|
||||||
|
x:Name="Mask"
|
||||||
|
Background="{DynamicResource ControlBackgroundNormalBrush}"
|
||||||
|
CornerRadius="{Binding Path=(assists:ControlAssist.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}" />
|
||||||
|
|
||||||
|
<!-- ItemsPresenter 展示子项,应用遮罩,超出圆角的部分会被自动裁切 -->
|
||||||
|
<ItemsPresenter>
|
||||||
|
<ItemsPresenter.OpacityMask>
|
||||||
|
<VisualBrush Visual="{Binding ElementName=Mask}" />
|
||||||
|
</ItemsPresenter.OpacityMask>
|
||||||
|
</ItemsPresenter>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|||||||
@@ -7,13 +7,16 @@ namespace Melskin.Utilities;
|
|||||||
internal class RelayCommand : ICommand
|
internal class RelayCommand : ICommand
|
||||||
{
|
{
|
||||||
private readonly Action<object?> execute;
|
private readonly Action<object?> execute;
|
||||||
|
private readonly Predicate<object?>? _canExecute;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当命令的可执行状态更改时发生的事件。
|
/// 当命令的可执行状态更改时发生的事件。
|
||||||
/// 此事件通知UI,当命令的CanExecute方法返回值发生变化时,需要重新查询命令的状态。
|
/// 此事件通知UI,当命令的CanExecute方法返回值发生变化时,需要重新查询命令的状态。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler? CanExecuteChanged;
|
public event EventHandler? CanExecuteChanged
|
||||||
|
{
|
||||||
|
add => CommandManager.RequerySuggested += value;
|
||||||
|
remove => CommandManager.RequerySuggested -= value;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 一个简单的ICommand实现,用于传递动作。此命令始终可以执行。
|
/// 一个简单的ICommand实现,用于传递动作。此命令始终可以执行。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,13 +27,18 @@ internal class RelayCommand : ICommand
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="parameter">传递给命令的参数。</param>
|
/// <param name="parameter">传递给命令的参数。</param>
|
||||||
/// <returns>返回一个布尔值,指示命令是否能够执行。对于此实现,总是返回true。</returns>
|
/// <returns>返回一个布尔值,指示命令是否能够执行。对于此实现,总是返回true。</returns>
|
||||||
public bool CanExecute(object? parameter) => true;
|
public bool CanExecute(object? parameter) => _canExecute == null || _canExecute(parameter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行命令。
|
/// 执行命令。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="parameter">传递给命令的参数。</param>
|
/// <param name="parameter">传递给命令的参数。</param>
|
||||||
public void Execute(object? parameter) => execute(parameter);
|
public void Execute(object? parameter) => execute(parameter);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通知命令管理器重新查询此命令的 CanExecute 状态。
|
||||||
|
/// </summary>
|
||||||
|
public void RaiseCanExecuteChanged() => CommandManager.InvalidateRequerySuggested();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -66,7 +74,14 @@ internal class RelayCommand<T> : ICommand
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="parameter">传递给命令的参数。</param>
|
/// <param name="parameter">传递给命令的参数。</param>
|
||||||
/// <returns>返回一个布尔值,指示命令是否能够执行。对于此实现,总是返回true。</returns>
|
/// <returns>返回一个布尔值,指示命令是否能够执行。对于此实现,总是返回true。</returns>
|
||||||
public bool CanExecute(object? parameter) => canExecute == null || canExecute((T?)parameter);
|
public bool CanExecute(object? parameter)
|
||||||
|
{
|
||||||
|
if (canExecute == null) return true;
|
||||||
|
|
||||||
|
// 使用安全的类型获取机制,防止 InvalidCastException
|
||||||
|
T? validParameter = GetSafeParameter(parameter);
|
||||||
|
return canExecute(validParameter);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行命令。
|
/// 执行命令。
|
||||||
@@ -74,13 +89,26 @@ internal class RelayCommand<T> : ICommand
|
|||||||
/// <param name="parameter">传递给命令的参数。</param>
|
/// <param name="parameter">传递给命令的参数。</param>
|
||||||
public void Execute(object? parameter)
|
public void Execute(object? parameter)
|
||||||
{
|
{
|
||||||
execute((T?)parameter);
|
T? validParameter = GetSafeParameter(parameter);
|
||||||
|
execute(validParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通知命令管理器重新查询此命令的CanExecute状态。
|
/// 通知命令管理器重新查询此命令的CanExecute状态。
|
||||||
/// 此方法用于在命令执行条件可能已更改时更新UI。
|
/// 此方法用于在命令执行条件可能已更改时更新UI。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
#pragma warning disable CS0067
|
|
||||||
public void RaiseCanExecuteChanged() => CommandManager.InvalidateRequerySuggested();
|
public void RaiseCanExecuteChanged() => CommandManager.InvalidateRequerySuggested();
|
||||||
|
/// <summary>
|
||||||
|
/// 安全地将 object 参数转换为泛型 T。如果类型不匹配,则返回 T 的默认值。
|
||||||
|
/// </summary>
|
||||||
|
private static T? GetSafeParameter(object? parameter)
|
||||||
|
{
|
||||||
|
if (parameter is T tParam)
|
||||||
|
{
|
||||||
|
return tParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 应对 WPF 绑定时可能会传入 null 的情况,特别是在 T 为值类型时
|
||||||
|
return default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -938,19 +938,23 @@
|
|||||||
|
|
||||||
</ms:FlexibleRowPanel>
|
</ms:FlexibleRowPanel>
|
||||||
<ms:FlexibleRowPanel LayoutMode="Auto" Spacing="20">
|
<ms:FlexibleRowPanel LayoutMode="Auto" Spacing="20">
|
||||||
<UniformGrid Columns="3">
|
<ListBox
|
||||||
<ListBox
|
HorizontalAlignment="Center"
|
||||||
HorizontalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
SelectedIndex="0"
|
||||||
SelectedIndex="1"
|
Style="{StaticResource TabGroupListBoxStyle}">
|
||||||
Style="{StaticResource TabGroupListBoxStyle}">
|
<ListBoxItem Content="Home" />
|
||||||
<ListBoxItem Content="Home" />
|
<ListBoxItem Content="Away" />
|
||||||
<ListBoxItem Content="Away" />
|
<ListBoxItem Content="Night" />
|
||||||
<ListBoxItem Content="Night" />
|
</ListBox>
|
||||||
</ListBox>
|
<ListBox
|
||||||
|
HorizontalAlignment="Center"
|
||||||
</UniformGrid>
|
VerticalAlignment="Center"
|
||||||
|
SelectedIndex="1">
|
||||||
|
<ListBoxItem Content="Home" />
|
||||||
|
<ListBoxItem Content="Away" />
|
||||||
|
<ListBoxItem Content="Night" />
|
||||||
|
</ListBox>
|
||||||
</ms:FlexibleRowPanel>
|
</ms:FlexibleRowPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel ms:ControlAssist.AnchorHeaderText="数据展示 TabControl">
|
<StackPanel ms:ControlAssist.AnchorHeaderText="数据展示 TabControl">
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Rv2WinColorConverter : IValueConverter
|
public class Rv2WinColorConverter : IValueConverter
|
||||||
{
|
{
|
||||||
public static Rv2WinColorConverter Instance { get; } = new Rv2WinColorConverter();
|
public static readonly Rv2WinColorConverter Instance = new();
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
var color = (Autodesk.Revit.DB.Color)value;
|
var color = (Autodesk.Revit.DB.Color)value;
|
||||||
//if (Autodesk.Revit.DB.SelectedColor.InvalidColorValue)
|
|
||||||
//{
|
|
||||||
//}
|
|
||||||
if (color is { IsValid: true })
|
if (color is { IsValid: true })
|
||||||
{
|
{
|
||||||
var rgb = Color.FromRgb(color.Red, color.Green, color.Blue);
|
var rgb = Color.FromRgb(color.Red, color.Green, color.Blue);
|
||||||
|
|||||||
Reference in New Issue
Block a user