mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-25 02:30:32 +08:00
Refactor ScopeAwareAdornerLayer
This commit is contained in:
@@ -45,16 +45,12 @@ public class ScopeAwareAdornerLayer : Canvas
|
||||
private static readonly AttachedProperty<ScopeAwareAdornerLayer?> SavedAdornerLayerProperty =
|
||||
AvaloniaProperty.RegisterAttached<Visual, Visual, ScopeAwareAdornerLayer?>("SavedAdornerLayer");
|
||||
|
||||
private static readonly MethodInfo AddLayerMethodInfo;
|
||||
|
||||
#endregion
|
||||
|
||||
static ScopeAwareAdornerLayer()
|
||||
{
|
||||
AdornedElementProperty.Changed.Subscribe(HandleAdornedElementChanged);
|
||||
AdornerProperty.Changed.Subscribe(HandleAdornerChanged);
|
||||
AddLayerMethodInfo =
|
||||
typeof(VisualLayerManager).GetMethod("AddLayer", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
}
|
||||
|
||||
public ScopeAwareAdornerLayer()
|
||||
@@ -333,11 +329,6 @@ public class ScopeAwareAdornerLayer : Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddLayerToVisualLayerManager(VisualLayerManager visualLayerManager, Control layer, int zindex)
|
||||
{
|
||||
AddLayerMethodInfo.Invoke(visualLayerManager, [layer, zindex]);
|
||||
}
|
||||
|
||||
private static ScopeAwareAdornerLayer InjectLayer(Layoutable layerHost)
|
||||
{
|
||||
var layer = FindAdornerLayer(layerHost);
|
||||
@@ -356,7 +347,7 @@ public class ScopeAwareAdornerLayer : Canvas
|
||||
layer.LayerHost = layerHost;
|
||||
if (layerHost is VisualLayerManager visualLayerManager)
|
||||
{
|
||||
AddLayerToVisualLayerManager(visualLayerManager, layer, visualLayerManager.ZIndex);
|
||||
visualLayerManager.AddLayer(layer, visualLayerManager.ZIndex);
|
||||
}
|
||||
else if (layerHost is ScrollContentPresenter scrollContentPresenter)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Reflection;
|
||||
using AtomUI.Reflection;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
|
||||
namespace AtomUI.Controls.Utils;
|
||||
|
||||
internal static class VisualLayerManagerReflectionExtensions
|
||||
{
|
||||
#region 反射信息定义
|
||||
|
||||
private static readonly Lazy<MethodInfo> AddLayerMethodInfo = new Lazy<MethodInfo>(() =>
|
||||
typeof(VisualLayerManager).GetMethodInfoOrThrow("AddLayer",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic));
|
||||
|
||||
#endregion
|
||||
|
||||
public static void AddLayer(this VisualLayerManager visualLayerManager, Control layer, int zindex)
|
||||
{
|
||||
AddLayerMethodInfo.Value.Invoke(visualLayerManager, [layer, zindex]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user