This commit is contained in:
GG Z
2025-07-31 20:12:24 +08:00
parent 4f6cd2137c
commit f209e7d3ad
426 changed files with 15854 additions and 6612 deletions

View File

@@ -0,0 +1,144 @@
namespace AntDesignWPF.Controls
{
using System.Windows;
using ContentControlBase = System.Windows.Controls.ContentControl;
/// <summary>
/// Tag for categorizing or markup.
/// </summary>
[TemplatePart(Name = PART_Close, Type = typeof(UIElement))]
public class Tag : ContentControlBase
{
#region Fileds
private const string PART_Close = "PART_Close";
private UIElement close;
#endregion
#region Events
public static readonly RoutedEvent ClosingEvent =
EventManager.RegisterRoutedEvent("Closing", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Tag));
/// <summary>
/// Occurs when closing the tag.
/// </summary>
public event RoutedEventHandler Closing
{
add { AddHandler(ClosingEvent, value); }
remove { RemoveHandler(ClosingEvent, value); }
}
public static readonly RoutedEvent ClosedEvent =
EventManager.RegisterRoutedEvent("Closed", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Tag));
/// <summary>
/// Occurs when a Tag is closed and is no longer visible.
/// </summary>
public event RoutedEventHandler Closed
{
add { AddHandler(ClosedEvent, value); }
remove { RemoveHandler(ClosedEvent, value); }
}
#endregion
#region Properties
public static readonly DependencyProperty ClosableProperty =
DependencyProperty.Register("Closable", typeof(bool), typeof(Tag), new PropertyMetadata(false, OnClosableChnaged));
/// <summary>
/// Gets/sets whether the Tag can be closed.
/// </summary>
public bool Closable
{
get { return (bool)GetValue(ClosableProperty); }
set { SetValue(ClosableProperty, value); }
}
private static void OnClosableChnaged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as Tag).SetCloseVisibility();
}
private void SetCloseVisibility()
{
if (close != null)
{
close.Visibility = Closable ? Visibility.Visible : Visibility.Collapsed;
}
}
public static readonly DependencyProperty ColorModeProperty =
DependencyProperty.Register("ColorMode", typeof(ColorMode?), typeof(Tag), new PropertyMetadata(null));
/// <summary>
/// Gets/sets the color mode of the tag.
/// </summary>
public ColorMode? ColorMode
{
get { return (ColorMode?)GetValue(ColorModeProperty); }
set { SetValue(ColorModeProperty, value); }
}
#endregion
#region Constructors
static Tag()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Tag), new FrameworkPropertyMetadata(typeof(Tag)));
}
#endregion
#region Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
close = GetTemplateChild(PART_Close) as UIElement;
if (close != null)
{
Loaded -= OnLoaded;
Loaded += OnLoaded;
close.MouseLeftButtonUp -= OnRaiseClosingEvent;
close.MouseLeftButtonUp += OnRaiseClosingEvent;
SetCloseVisibility();
}
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Closing -= OnClosing;
Closing += OnClosing;
}
private void OnRaiseClosingEvent(object sender, RoutedEventArgs e)
{
e.Handled = true;
RaiseEvent(new RoutedEventArgs(ClosingEvent, this));
}
private void OnClosing(object sender, RoutedEventArgs e)
{
SetCurrentValue(VisibilityProperty, Visibility.Collapsed);
RaiseEvent(new RoutedEventArgs(ClosedEvent, this));
}
#endregion
}
public enum ColorMode : byte
{
Colorful, Inverse
}
}

View File

@@ -0,0 +1,158 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:Behaviors="clr-namespace:AntDesignWPF.Behaviors"
xmlns:controls="clr-namespace:AntDesignWPF.Controls"
xmlns:helpers="clr-namespace:AntDesignWPF.Helpers"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AntDesignWPF;component/Themes/Converters.xaml" />
<ResourceDictionary Source="pack://application:,,,/AntDesignWPF;component/Themes/Animations.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type controls:Tag}">
<Setter Property="Padding" Value="8,4" />
<Setter Property="Margin" Value="0,0,8,0" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource TagFontSize}" />
<Setter Property="FontFamily" Value="{DynamicResource FontFamily}" />
<Setter Property="BorderBrush" Value="{DynamicResource AntDesign.Brush.BorderPrimary}" />
<Setter Property="Background" Value="{DynamicResource AntDesign.Brush.BackgroundContainer}" />
<Setter Property="Foreground" Value="{DynamicResource AntDesign.Brush.TextPrimary}" />
<Setter Property="BorderThickness" Value="{DynamicResource BorderThicknessBase}" />
<Setter Property="helpers:AntControl.BorderStyle" Value="{DynamicResource BorderStyleBase}" />
<Setter Property="helpers:AntControl.CornerRadius" Value="{DynamicResource BorderRadiusBase}" />
<Setter Property="RenderTransformOrigin" Value="0,0.5" />
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform />
</Setter.Value>
</Setter>
<Setter Property="Behaviors:StylizedBehaviors.Behaviors">
<Setter.Value>
<Behaviors:StylizedBehaviorCollection>
<Behaviors:VisibilityBehavior>
<Behaviors:VisibilityBehavior.Appear>
<Storyboard>
<DoubleAnimation
Duration="0:0:0.2"
EasingFunction="{StaticResource EaseInOutCirc}"
From="0"
Storyboard.TargetProperty="Opacity"
To="1" />
</Storyboard>
</Behaviors:VisibilityBehavior.Appear>
<Behaviors:VisibilityBehavior.Leave>
<Storyboard FillBehavior="Stop">
<DoubleAnimation
Duration="0:0:0.3"
EasingFunction="{StaticResource EaseInOutCirc}"
Storyboard.TargetProperty="Opacity"
To="0" />
<DoubleAnimation
Duration="0:0:0.3"
EasingFunction="{StaticResource EaseInOutCirc}"
Storyboard.TargetProperty="RenderTransform.ScaleX"
To="0.2" />
<DoubleAnimation
Duration="0:0:0.3"
EasingFunction="{StaticResource EaseInOutCirc}"
Storyboard.TargetProperty="RenderTransform.ScaleY"
To="0.2" />
</Storyboard>
</Behaviors:VisibilityBehavior.Leave>
</Behaviors:VisibilityBehavior>
</Behaviors:StylizedBehaviorCollection>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:Tag}">
<Grid>
<!-- Effect -->
<Border
BorderBrush="{DynamicResource AntDesign.Brush.Primary}"
BorderThickness="0"
CornerRadius="{TemplateBinding helpers:AntControl.CornerRadius}"
Focusable="False"
Margin="-1"
Opacity="0.35"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="Effect" />
<!-- Border -->
<controls:AntBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderStyle="{TemplateBinding helpers:AntControl.BorderStyle}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding helpers:AntControl.CornerRadius}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
UseLayoutRounding="True"
x:Name="Border">
<!-- Content -->
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type controls:Icon}" x:Key="Ant.IconClose">
<Setter Property="Opacity" Value="0.65" />
<Setter Property="Margin" Value="3,0,0,0" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<!-- Content -->
<ColumnDefinition Width="*" />
<!-- Close Button -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<controls:Icon
Focusable="False"
Grid.Column="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Style="{StaticResource Ant.IconClose}"
Type="close"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="PART_Close" />
</Grid>
</controls:AntBorder>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ColorMode" Value="Colorful">
<Setter Property="BorderBrush" TargetName="Effect" Value="{Binding Foreground, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="Background" TargetName="Border" Value="{Binding Foreground, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorPaletteConverter}, ConverterParameter=1}" />
<Setter Property="BorderBrush" TargetName="Border" Value="{Binding Foreground, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorPaletteConverter}, ConverterParameter=3}" />
</Trigger>
<Trigger Property="ColorMode" Value="Inverse">
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" TargetName="Effect" Value="{Binding Background, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="BorderBrush" TargetName="Border" Value="{Binding Background, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
<EventTrigger RoutedEvent="MouseLeftButtonUp">
<BeginStoryboard Storyboard="{StaticResource Ant.ClickAnimating}" />
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.85" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>