From d99697f4ae211ffbe5ddd16a5f73ac641a0251de Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 31 May 2023 12:58:21 +0100 Subject: [PATCH] fixes the overlay popup glitch where it renders at 0,0 before applying the offet. use the media context api to sync with layout and render. --- src/Avalonia.Base/Media/MediaContext.cs | 9 +++++++-- src/Avalonia.Controls/Primitives/OverlayPopupHost.cs | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Base/Media/MediaContext.cs b/src/Avalonia.Base/Media/MediaContext.cs index c261dd80b8..a41107360a 100644 --- a/src/Avalonia.Base/Media/MediaContext.cs +++ b/src/Avalonia.Base/Media/MediaContext.cs @@ -212,7 +212,12 @@ internal partial class MediaContext : ICompositorScheduler } while (count > 0); } - + + /// + /// Executes the callback in the layout pass that will occur + /// immediately before the next rendered frame. + /// + /// Code to execute. public void BeginInvokeOnRender(Action callback) { if (_invokeOnRenderCallbacks == null) @@ -224,4 +229,4 @@ internal partial class MediaContext : ICompositorScheduler if (!_isRendering) ScheduleRender(true); } -} \ No newline at end of file +} diff --git a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs index 2236d87dd1..5dd0f23e8e 100644 --- a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs +++ b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs @@ -120,11 +120,11 @@ namespace Avalonia.Controls.Primitives void IManagedPopupPositionerPopup.MoveAndResize(Point devicePoint, Size virtualSize) { _lastRequestedPosition = devicePoint; - Dispatcher.UIThread.Post(() => + MediaContext.Instance.BeginInvokeOnRender(() => { - OverlayLayer.SetLeft(this, _lastRequestedPosition.X); - OverlayLayer.SetTop(this, _lastRequestedPosition.Y); - }, DispatcherPriority.Render); + Canvas.SetLeft(this, _lastRequestedPosition.X); + Canvas.SetTop(this, _lastRequestedPosition.Y); + }); } double IManagedPopupPositionerPopup.Scaling => 1;