|
|
|
@ -1,7 +1,11 @@ |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
using Avalonia.Animation; |
|
|
|
using Avalonia.Controls.Metadata; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
|
|
|
|
#nullable enable |
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
@ -36,8 +40,8 @@ namespace Avalonia.Controls |
|
|
|
[PseudoClasses(":expanded", ":up", ":down", ":left", ":right")] |
|
|
|
public class Expander : HeaderedContentControl |
|
|
|
{ |
|
|
|
public static readonly StyledProperty<IPageTransition> ContentTransitionProperty = |
|
|
|
AvaloniaProperty.Register<Expander, IPageTransition>(nameof(ContentTransition)); |
|
|
|
public static readonly StyledProperty<IPageTransition?> ContentTransitionProperty = |
|
|
|
AvaloniaProperty.Register<Expander, IPageTransition?>(nameof(ContentTransition)); |
|
|
|
|
|
|
|
public static readonly StyledProperty<ExpandDirection> ExpandDirectionProperty = |
|
|
|
AvaloniaProperty.Register<Expander, ExpandDirection>(nameof(ExpandDirection), ExpandDirection.Down); |
|
|
|
@ -50,6 +54,7 @@ namespace Avalonia.Controls |
|
|
|
defaultBindingMode: Data.BindingMode.TwoWay); |
|
|
|
|
|
|
|
private bool _isExpanded; |
|
|
|
private CancellationTokenSource? _lastTransitionCts; |
|
|
|
|
|
|
|
static Expander() |
|
|
|
{ |
|
|
|
@ -61,7 +66,7 @@ namespace Avalonia.Controls |
|
|
|
UpdatePseudoClasses(ExpandDirection); |
|
|
|
} |
|
|
|
|
|
|
|
public IPageTransition ContentTransition |
|
|
|
public IPageTransition? ContentTransition |
|
|
|
{ |
|
|
|
get => GetValue(ContentTransitionProperty); |
|
|
|
set => SetValue(ContentTransitionProperty, value); |
|
|
|
@ -83,19 +88,23 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void OnIsExpandedChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
protected virtual async void OnIsExpandedChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
if (Content != null && ContentTransition != null && Presenter is Visual visualContent) |
|
|
|
{ |
|
|
|
bool forward = ExpandDirection == ExpandDirection.Left || |
|
|
|
ExpandDirection == ExpandDirection.Up; |
|
|
|
|
|
|
|
_lastTransitionCts?.Cancel(); |
|
|
|
_lastTransitionCts = new CancellationTokenSource(); |
|
|
|
|
|
|
|
if (IsExpanded) |
|
|
|
{ |
|
|
|
ContentTransition.Start(null, visualContent, forward); |
|
|
|
await ContentTransition.Start(null, visualContent, forward, _lastTransitionCts.Token); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ContentTransition.Start(visualContent, null, !forward); |
|
|
|
await ContentTransition.Start(visualContent, null, forward, _lastTransitionCts.Token); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|