diff --git a/src/AtomUI.Controls/ArrowDecoratedBox/ArrowDecoratedBox.cs b/src/AtomUI.Controls/ArrowDecoratedBox/ArrowDecoratedBox.cs index 6128e6548..02547ce53 100644 --- a/src/AtomUI.Controls/ArrowDecoratedBox/ArrowDecoratedBox.cs +++ b/src/AtomUI.Controls/ArrowDecoratedBox/ArrowDecoratedBox.cs @@ -1,13 +1,10 @@ -using System.Reactive.Disposables; -using AtomUI.Controls.Utils; -using AtomUI.Media; +using AtomUI.Media; using AtomUI.Styling; using AtomUI.Utils; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Layout; -using Avalonia.LogicalTree; using Avalonia.Media; using Avalonia.Metadata; @@ -138,8 +135,7 @@ public class ArrowDecoratedBox : TemplatedControl, get => GetValue(ChildProperty); set => SetValue(ChildProperty, value); } - - private bool _initialized = false; + private IControlCustomStyle _customStyle; private Geometry? _arrowGeometry; private Rect _contentRect; @@ -233,7 +229,7 @@ public class ArrowDecoratedBox : TemplatedControl, _needGenerateArrowVertexPoint = true; } - if (_initialized && VisualRoot is not null) { + if (VisualRoot is not null) { BuildGeometry(true); _arrowRect = GetArrowRect(DesiredSize); } diff --git a/src/AtomUI.Controls/Flyouts/Flyout.cs b/src/AtomUI.Controls/Flyouts/Flyout.cs index 112aede57..0c9c94393 100644 --- a/src/AtomUI.Controls/Flyouts/Flyout.cs +++ b/src/AtomUI.Controls/Flyouts/Flyout.cs @@ -389,12 +389,6 @@ public class Flyout : PopupFlyoutBase motionActor.SceneParent = topLevel; motionActor.Completed += (sender, args) => { - if (flyoutPresenter.Child is not null) { - var child = flyoutPresenter.Child; - UIStructureUtils.ClearLogicalParentRecursive(child, null); - UIStructureUtils.ClearVisualParentRecursive(child, null); - } - base.ShowAtCore(placementTarget, showAtPointer); if (Popup.Host is WindowBase window) { window.PlatformImpl!.SetTopmost(true); diff --git a/src/AtomUI.Controls/Flyouts/FlyoutHost.cs b/src/AtomUI.Controls/Flyouts/FlyoutHost.cs index f5ea34bd2..ece768a31 100644 --- a/src/AtomUI.Controls/Flyouts/FlyoutHost.cs +++ b/src/AtomUI.Controls/Flyouts/FlyoutHost.cs @@ -155,9 +155,9 @@ public class FlyoutHost : Control PlacementProperty.OverrideDefaultValue(PlacementMode.Top); } - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + public sealed override void ApplyTemplate() { - base.OnAttachedToLogicalTree(e); + base.ApplyTemplate(); if (!_initialized) { if (AnchorTarget is not null) { ((ISetLogicalParent)AnchorTarget).SetParent(this); diff --git a/src/AtomUI.Controls/Loading/LoadingMaskHost.cs b/src/AtomUI.Controls/Loading/LoadingMaskHost.cs index 57770b779..60263ddc0 100644 --- a/src/AtomUI.Controls/Loading/LoadingMaskHost.cs +++ b/src/AtomUI.Controls/Loading/LoadingMaskHost.cs @@ -131,22 +131,17 @@ public class LoadingMaskHost : Control, IControlCustomStyle } } - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + public sealed override void ApplyTemplate() { - base.OnAttachedToLogicalTree(e); + base.ApplyTemplate(); if (!_initialized) { - _customStyle.HandleAttachedToLogicalTree(e); + if (MaskTarget is not null) { + ((ISetLogicalParent)MaskTarget).SetParent(this); + VisualChildren.Add(MaskTarget); + } _initialized = true; } } - - void IControlCustomStyle.HandleAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) - { - if (MaskTarget is not null) { - ((ISetLogicalParent)MaskTarget).SetParent(this); - VisualChildren.Add(MaskTarget); - } - } protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { diff --git a/src/AtomUI.Controls/Popup/Popup.cs b/src/AtomUI.Controls/Popup/Popup.cs index 19d5faf91..9ac9a5557 100644 --- a/src/AtomUI.Controls/Popup/Popup.cs +++ b/src/AtomUI.Controls/Popup/Popup.cs @@ -66,10 +66,10 @@ public class Popup : AbstractPopup { IsLightDismissEnabled = false; } - - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + + public sealed override void ApplyTemplate() { - base.OnAttachedToLogicalTree(e); + base.ApplyTemplate(); if (!_initialized) { BindUtils.CreateGlobalTokenBinding(this, MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary); _initialized = true; diff --git a/src/AtomUI.Controls/Popup/PopupShadowLayer.cs b/src/AtomUI.Controls/Popup/PopupShadowLayer.cs index f36438224..9a08a0f22 100644 --- a/src/AtomUI.Controls/Popup/PopupShadowLayer.cs +++ b/src/AtomUI.Controls/Popup/PopupShadowLayer.cs @@ -8,7 +8,6 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives.PopupPositioning; using Avalonia.Media; -using Avalonia.Threading; namespace AtomUI.Controls; diff --git a/src/AtomUI.Controls/Primitives/MotionGhostControl.cs b/src/AtomUI.Controls/Primitives/MotionGhostControl.cs index bd47e9e10..2b119a4d2 100644 --- a/src/AtomUI.Controls/Primitives/MotionGhostControl.cs +++ b/src/AtomUI.Controls/Primitives/MotionGhostControl.cs @@ -87,15 +87,15 @@ internal class MotionGhostControl : Control, INotifyCaptureGhostBitmap } } - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + public sealed override void ApplyTemplate() { - base.OnAttachedToLogicalTree(e); + base.ApplyTemplate(); if (!_initialized) { IsHitTestVisible = false; _layout = new Canvas(); VisualChildren.Add(_layout); - LogicalChildren.Add(_layout); + ((ISetLogicalParent)_layout).SetParent(this); var shadowThickness = Shadows.Thickness(); var offsetX = shadowThickness.Left; diff --git a/src/AtomUI.Controls/Primitives/ShadowRenderer.cs b/src/AtomUI.Controls/Primitives/ShadowRenderer.cs index a6396f422..f3a0140ea 100644 --- a/src/AtomUI.Controls/Primitives/ShadowRenderer.cs +++ b/src/AtomUI.Controls/Primitives/ShadowRenderer.cs @@ -53,9 +53,9 @@ internal class ShadowRenderer : Control MaskContentBackgroundProperty.OverrideDefaultValue(new SolidColorBrush(Colors.White)); } - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + public sealed override void ApplyTemplate() { - base.OnAttachedToLogicalTree(e); + base.ApplyTemplate(); if (!_initialized) { HorizontalAlignment = HorizontalAlignment.Stretch; VerticalAlignment = VerticalAlignment.Stretch;