mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-26 03:00:28 +08:00
Refactor CollapseItem
This commit is contained in:
@@ -163,7 +163,6 @@ public class Alert : TemplatedControl,
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_tokenBindingsDisposable = new CompositeDisposable();
|
||||
SetupCloseButton();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
@@ -179,6 +178,7 @@ public class Alert : TemplatedControl,
|
||||
SharedTokenKey.BorderThickness,
|
||||
BindingPriority.Template,
|
||||
new RenderScaleAwareThicknessConfigure(this)));
|
||||
SetupCloseButton();
|
||||
}
|
||||
|
||||
private void SetupCloseButton()
|
||||
|
||||
@@ -147,21 +147,6 @@ public class CountBadge : Control,
|
||||
this.BindAnimationProperties(IsMotionEnabledProperty, IsWaveAnimationEnabledProperty);
|
||||
}
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
if (!_isInitialized)
|
||||
{
|
||||
if (DecoratedTarget is null)
|
||||
{
|
||||
CreateBadgeAdorner();
|
||||
}
|
||||
|
||||
SetupShowZero();
|
||||
_isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private CountBadgeAdorner CreateBadgeAdorner()
|
||||
{
|
||||
if (_badgeAdorner is null)
|
||||
@@ -224,6 +209,12 @@ public class CountBadge : Control,
|
||||
{
|
||||
PrepareAdorner();
|
||||
}
|
||||
if (DecoratedTarget is null)
|
||||
{
|
||||
CreateBadgeAdorner();
|
||||
}
|
||||
|
||||
SetupShowZero();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
|
||||
@@ -175,8 +175,6 @@ internal class CountBadgeAdorner : TemplatedControl
|
||||
_indicatorMotionActor.IsVisible = false;
|
||||
_needInitialHide = false;
|
||||
}
|
||||
|
||||
BuildBoxShadow();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
@@ -185,6 +183,12 @@ internal class CountBadgeAdorner : TemplatedControl
|
||||
BuildCountText();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
BuildBoxShadow();
|
||||
}
|
||||
|
||||
private void BuildBoxShadow()
|
||||
{
|
||||
if (BadgeShadowColor is not null)
|
||||
|
||||
@@ -185,6 +185,19 @@ public class DotBadge : Control,
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
if (DecoratedTarget is null)
|
||||
{
|
||||
CreateDotBadgeAdorner();
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareAdorner();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
@@ -221,19 +234,6 @@ public class DotBadge : Control,
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
if (DecoratedTarget is null)
|
||||
{
|
||||
CreateDotBadgeAdorner();
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareAdorner();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
|
||||
@@ -152,15 +152,6 @@ public class RibbonBadge : Control,
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
if (DecoratedTarget is null)
|
||||
{
|
||||
CreateBadgeAdorner();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
@@ -247,6 +238,10 @@ public class RibbonBadge : Control,
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
PrepareAdorner();
|
||||
if (DecoratedTarget is null)
|
||||
{
|
||||
CreateBadgeAdorner();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
|
||||
@@ -177,11 +177,6 @@ internal class CheckBoxIndicator : Control,
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, BorderThicknessProperty,
|
||||
SharedTokenKey.BorderThickness, BindingPriority.Template,
|
||||
new RenderScaleAwareThicknessConfigure(this)));
|
||||
}
|
||||
|
||||
public override void ApplyTemplate()
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
SetupTransitions();
|
||||
}
|
||||
|
||||
|
||||
@@ -178,8 +178,7 @@ public class Collapse : SelectingItemsControl,
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
SetupEffectiveBorderThickness();
|
||||
SetupSelectionMode();
|
||||
|
||||
}
|
||||
|
||||
protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
|
||||
@@ -373,5 +372,7 @@ public class Collapse : SelectingItemsControl,
|
||||
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, BorderThicknessProperty,
|
||||
SharedTokenKey.BorderThickness,
|
||||
BindingPriority.Template, new RenderScaleAwareThicknessConfigure(this)));
|
||||
SetupEffectiveBorderThickness();
|
||||
SetupSelectionMode();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using AtomUI.Controls.Utils;
|
||||
using System.Diagnostics;
|
||||
using AtomUI.Controls.Utils;
|
||||
using AtomUI.IconPkg;
|
||||
using AtomUI.IconPkg.AntDesign;
|
||||
using AtomUI.MotionScene;
|
||||
@@ -10,6 +11,7 @@ using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
@@ -230,12 +232,12 @@ public class CollapseItem : HeaderedContentControl,
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
ExpandIcon ??= AntDesignIconPackage.RightOutlined();
|
||||
ExpandIcon.SetTemplatedParent(this);
|
||||
base.OnApplyTemplate(e);
|
||||
_motionActor = e.NameScope.Find<MotionActorControl>(CollapseItemTheme.ContentMotionActorPart);
|
||||
_headerDecorator = e.NameScope.Find<Border>(CollapseItemTheme.HeaderDecoratorPart);
|
||||
_expandButton = e.NameScope.Find<IconButton>(CollapseItemTheme.ExpandButtonPart);
|
||||
|
||||
// 必须放在这里,因为依赖 _motionActor 是否设置
|
||||
_tempAnimationDisabled = true;
|
||||
HandleSelectedChanged();
|
||||
_tempAnimationDisabled = false;
|
||||
@@ -245,6 +247,22 @@ public class CollapseItem : HeaderedContentControl,
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
SetupDefaultExpandIcon();
|
||||
}
|
||||
|
||||
private void SetupDefaultExpandIcon()
|
||||
{
|
||||
if (ExpandIcon is null)
|
||||
{
|
||||
ClearValue(ExpandIconProperty);
|
||||
SetValue(ExpandIconProperty, AntDesignIconPackage.RightOutlined(), BindingPriority.Template);
|
||||
}
|
||||
Debug.Assert(ExpandIcon != null);
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
@@ -257,7 +275,8 @@ public class CollapseItem : HeaderedContentControl,
|
||||
}
|
||||
}
|
||||
|
||||
if (change.Property == AddOnContentProperty)
|
||||
if (change.Property == AddOnContentProperty ||
|
||||
change.Property == ExpandIconProperty)
|
||||
{
|
||||
if (change.OldValue is Control oldControl)
|
||||
{
|
||||
@@ -268,6 +287,10 @@ public class CollapseItem : HeaderedContentControl,
|
||||
{
|
||||
newControl.SetTemplatedParent(this);
|
||||
}
|
||||
if (change.Property == ExpandIconProperty)
|
||||
{
|
||||
SetupDefaultExpandIcon();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user