feat:Redesign the usage pattern of WHAnimationHelper once more to deliver a superior axaml editing and consumption experience.

This commit is contained in:
望尘空忧
2025-08-10 16:37:03 +08:00
parent c801c4eec4
commit b9e104a8b8
4 changed files with 160 additions and 93 deletions

View File

@@ -1,5 +1,11 @@
using Avalonia.Controls;
using System;
using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Styling;
using Ursa.Controls;
using Ursa.Helpers;
@@ -7,17 +13,42 @@ namespace Ursa.Demo.Pages;
public partial class NavMenuDemo : UserControl
{
private readonly NavMenuAnimationHelper _animationHelper;
public NavMenuDemo()
{
InitializeComponent();
_animationHelper = new NavMenuAnimationHelper(menu);
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
_animationHelper.Start();
}
public static WHAnimationHelperCreateAnimationDelegate NavMenuAnimation { get; } =
(_, oldDesiredSize, newDesiredSize) =>
{
if (oldDesiredSize.Width > newDesiredSize.Width)
newDesiredSize = newDesiredSize.WithWidth(newDesiredSize.Width + 20);
return new Animation
{
Duration = TimeSpan.FromMilliseconds(300),
Easing = new CubicEaseInOut(),
FillMode = FillMode.None,
Children =
{
new KeyFrame
{
Cue = new Cue(0.0),
Setters =
{
new Setter(WidthProperty, oldDesiredSize.Width),
new Setter(HeightProperty, oldDesiredSize.Height)
}
},
new KeyFrame
{
Cue = new Cue(1.0),
Setters =
{
new Setter(WidthProperty, newDesiredSize.Width),
new Setter(HeightProperty, newDesiredSize.Height)
}
}
}
};
};
}