misc:Rename WHAnimationHelper to SizeAnimationHelper to make its purpose immediately clear and eliminate any ambiguity caused by the cryptic “WH.”

This commit is contained in:
望尘空忧
2025-08-18 22:06:47 +08:00
parent b9e104a8b8
commit df23e6263c
3 changed files with 15 additions and 15 deletions

View File

@@ -41,9 +41,9 @@
ItemsSource="{Binding MenuItems}" ItemsSource="{Binding MenuItems}"
SelectedItem="{Binding SelectedMenuItem}" SelectedItem="{Binding SelectedMenuItem}"
SubMenuBinding="{Binding Children}" SubMenuBinding="{Binding Children}"
u:WHAnimationHelper.TriggerAvaloniaProperty="{x:Static u:NavMenu.IsHorizontalCollapsedProperty}" u:SizeAnimationHelper.TriggerAvaloniaProperty="{x:Static u:NavMenu.IsHorizontalCollapsedProperty}"
u:WHAnimationHelper.CreateAnimation="{x:Static views:NavMenuDemo.NavMenuAnimation}" u:SizeAnimationHelper.CreateAnimation="{x:Static views:NavMenuDemo.NavMenuAnimation}"
u:WHAnimationHelper.EnableWHAnimation="True"> u:SizeAnimationHelper.EnableWHAnimation="True">
<u:NavMenu.Styles> <u:NavMenu.Styles>
<Style x:DataType="vm:MenuItem" Selector="u|NavMenuItem"> <Style x:DataType="vm:MenuItem" Selector="u|NavMenuItem">
<Setter Property="IsSeparator" Value="{Binding IsSeparator}" /> <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />

View File

@@ -18,7 +18,7 @@ public partial class NavMenuDemo : UserControl
InitializeComponent(); InitializeComponent();
} }
public static WHAnimationHelperCreateAnimationDelegate NavMenuAnimation { get; } = public static SizeAnimationHelperAnimationGeneratorDelegate NavMenuAnimation { get; } =
(_, oldDesiredSize, newDesiredSize) => (_, oldDesiredSize, newDesiredSize) =>
{ {
if (oldDesiredSize.Width > newDesiredSize.Width) if (oldDesiredSize.Width > newDesiredSize.Width)

View File

@@ -8,25 +8,25 @@ using Avalonia.Styling;
namespace Ursa.Helpers; namespace Ursa.Helpers;
public delegate Animation WHAnimationHelperCreateAnimationDelegate(Control animationTargetControl, Size oldDesiredSize, public delegate Animation SizeAnimationHelperAnimationGeneratorDelegate(Control animationTargetControl, Size oldDesiredSize,
Size newDesiredSize); Size newDesiredSize);
public class WHAnimationHelper : AvaloniaObject public class SizeAnimationHelper : AvaloniaObject
{ {
public static readonly AttachedProperty<WHAnimationHelperCreateAnimationDelegate> CreateAnimationProperty = public static readonly AttachedProperty<SizeAnimationHelperAnimationGeneratorDelegate> CreateAnimationProperty =
AvaloniaProperty AvaloniaProperty
.RegisterAttached<WHAnimationHelper, Control, WHAnimationHelperCreateAnimationDelegate>( .RegisterAttached<SizeAnimationHelper, Control, SizeAnimationHelperAnimationGeneratorDelegate>(
"CreateAnimation", CreateAnimationPropertyDefaultValue); "CreateAnimation", CreateAnimationPropertyDefaultValue);
internal static readonly AttachedProperty<CancellationTokenSource?> AnimationCancellationTokenSourceProperty = internal static readonly AttachedProperty<CancellationTokenSource?> AnimationCancellationTokenSourceProperty =
AvaloniaProperty.RegisterAttached<WHAnimationHelper, Control, CancellationTokenSource?>( AvaloniaProperty.RegisterAttached<SizeAnimationHelper, Control, CancellationTokenSource?>(
"AnimationCancellationTokenSource"); "AnimationCancellationTokenSource");
public static readonly AttachedProperty<AvaloniaProperty?> TriggerAvaloniaPropertyProperty = public static readonly AttachedProperty<AvaloniaProperty?> TriggerAvaloniaPropertyProperty =
AvaloniaProperty.RegisterAttached<WHAnimationHelper, Control, AvaloniaProperty?>("TriggerAvaloniaProperty"); AvaloniaProperty.RegisterAttached<SizeAnimationHelper, Control, AvaloniaProperty?>("TriggerAvaloniaProperty");
public static readonly AttachedProperty<bool> EnableWHAnimationProperty = public static readonly AttachedProperty<bool> EnableWHAnimationProperty =
AvaloniaProperty.RegisterAttached<WHAnimationHelper, Control, bool>("EnableWHAnimation"); AvaloniaProperty.RegisterAttached<SizeAnimationHelper, Control, bool>("EnableWHAnimation");
private static Animation CreateAnimationPropertyDefaultValue(Control animationTargetControl, Size oldDesiredSize, private static Animation CreateAnimationPropertyDefaultValue(Control animationTargetControl, Size oldDesiredSize,
Size newDesiredSize) Size newDesiredSize)
@@ -61,12 +61,12 @@ public class WHAnimationHelper : AvaloniaObject
} }
public static void SetCreateAnimation(Control obj, WHAnimationHelperCreateAnimationDelegate value) public static void SetCreateAnimation(Control obj, SizeAnimationHelperAnimationGeneratorDelegate value)
{ {
obj.SetValue(CreateAnimationProperty, value); obj.SetValue(CreateAnimationProperty, value);
} }
public static WHAnimationHelperCreateAnimationDelegate GetCreateAnimation(Control obj) public static SizeAnimationHelperAnimationGeneratorDelegate GetCreateAnimation(Control obj)
{ {
return obj.GetValue(CreateAnimationProperty); return obj.GetValue(CreateAnimationProperty);
} }
@@ -101,14 +101,14 @@ public class WHAnimationHelper : AvaloniaObject
if (triggerProperty == null) if (triggerProperty == null)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"WHAnimationHelper requires TriggerAvaloniaProperty to be set when EnableWHAnimation is true."); "SizeAnimationHelper requires TriggerAvaloniaProperty to be set when EnableWHAnimation is true.");
} }
if (triggerProperty == Visual.BoundsProperty || if (triggerProperty == Visual.BoundsProperty ||
triggerProperty == Layoutable.DesiredSizeProperty) triggerProperty == Layoutable.DesiredSizeProperty)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"WHAnimationHelper does not support Visual.BoundsProperty or Layoutable.DesiredSizeProperty as trigger property."); "SizeAnimationHelper does not support Visual.BoundsProperty or Layoutable.DesiredSizeProperty as trigger property.");
} }
obj.Loaded += ObjOnLoaded; obj.Loaded += ObjOnLoaded;