Refactor Popup

This commit is contained in:
chinboy
2025-02-10 11:39:08 +08:00
parent 6b902da18d
commit a38bac6744
3 changed files with 15 additions and 17 deletions
+3 -2
View File
@@ -7,6 +7,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives.PopupPositioning;
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Metadata;
using Avalonia.Styling;
@@ -127,9 +128,9 @@ public class Flyout : PopupFlyoutBase
public Flyout()
{
TokenResourceBinder.CreateTokenBinding(this, MotionDurationTokenProperty,
TokenResourceBinder.CreateGlobalTokenBinding(this, MotionDurationTokenProperty,
SharedTokenKey.MotionDurationMid);
TokenResourceBinder.CreateTokenBinding(this, MaskShadowsProperty,
TokenResourceBinder.CreateGlobalTokenBinding(this, MaskShadowsProperty,
SharedTokenKey.BoxShadowsSecondary);
}
+10 -6
View File
@@ -155,16 +155,20 @@ public class FlyoutHost : Control
_flyoutStateHelper = new FlyoutStateHelper();
}
public override void ApplyTemplate()
{
base.ApplyTemplate();
TokenResourceBinder.CreateTokenBinding(this, MarginToAnchorProperty, SharedTokenKey.MarginXXS);
SetupFlyoutProperties();
}
// public override void ApplyTemplate()
// {
// // TODO 需要审查到底是否合适
// base.ApplyTemplate();
// TokenResourceBinder.CreateTokenBinding(this, MarginToAnchorProperty, SharedTokenKey.MarginXXS);
// SetupFlyoutProperties();
// }
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
TokenResourceBinder.CreateTokenBinding(this, MarginToAnchorProperty, SharedTokenKey.MarginXXS);
SetupFlyoutProperties();
BindUtils.RelayBind(this, AnchorTargetProperty, _flyoutStateHelper, FlyoutStateHelper.AnchorTargetProperty);
BindUtils.RelayBind(this, FlyoutProperty, _flyoutStateHelper, FlyoutStateHelper.FlyoutProperty);
BindUtils.RelayBind(this, MouseEnterDelayProperty, _flyoutStateHelper,
+2 -9
View File
@@ -75,7 +75,6 @@ public class Popup : AvaloniaPopup
private PopupShadowLayer? _shadowLayer;
private CompositeDisposable? _compositeDisposable;
private IDisposable? _selfLightDismissDisposable;
private bool _initialized;
private ManagedPopupPositionerInfo? _managedPopupPositioner;
private bool _isNeedFlip = true;
private bool _openAnimating;
@@ -102,14 +101,8 @@ public class Popup : AvaloniaPopup
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
if (!_initialized)
{
TokenResourceBinder.CreateTokenBinding(this, MaskShadowsProperty,
SharedTokenKey.BoxShadowsSecondary);
TokenResourceBinder.CreateTokenBinding(this, MotionDurationProperty,
SharedTokenKey.MotionDurationMid);
_initialized = true;
}
TokenResourceBinder.CreateTokenBinding(this, MaskShadowsProperty, SharedTokenKey.BoxShadowsSecondary);
TokenResourceBinder.CreateTokenBinding(this, MotionDurationProperty, SharedTokenKey.MotionDurationMid);
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)