From 5b14b426520e2d29fae8386407589afa098775a5 Mon Sep 17 00:00:00 2001 From: amwx <40413319+amwx@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:09:53 -0400 Subject: [PATCH] Fix crash in ItemsRepeater_ViewportManager --- .../UI/Controls/Repeater/ViewportManager.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/FluentAvalonia/UI/Controls/Repeater/ViewportManager.cs b/src/FluentAvalonia/UI/Controls/Repeater/ViewportManager.cs index 791a5a89..b2a153b8 100644 --- a/src/FluentAvalonia/UI/Controls/Repeater/ViewportManager.cs +++ b/src/FluentAvalonia/UI/Controls/Repeater/ViewportManager.cs @@ -365,10 +365,17 @@ private Control GetImmediateChildOfRepeater(Control descendant) parent = (Control)parent.GetVisualParent(); } + // This is what WinUI does, but this can be hit in Avalonia... + // My repro: ItemsRepeater -> Control w/ Popup -> ListBox in Popup + // Select item in the ListBox, we hit this + // Looking at Avalonia's port of ItemsRepeater, they just return + // null if parent is null, so that's what I'll do + //if (parent == null) + //{ + // throw new InvalidOperationException("OnBringIntoViewRequested called with args.target element not under the ItemsRepeater that recieved the call"); + //} if (parent == null) - { - throw new InvalidOperationException("OnBringIntoViewRequested called with args.target element not under the ItemsRepeater that recieved the call"); - } + return null; return targetChild; }