From 5f77d26c42f1ad08ab7017701d55e1dd8bd67e04 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 26 Jun 2020 14:08:48 +0200 Subject: [PATCH] Don't throw when a BringIntoView received from non-descendent. The event can come from a child `Popup`. Fixes #4176. --- src/Avalonia.Controls/Repeater/ViewportManager.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Repeater/ViewportManager.cs b/src/Avalonia.Controls/Repeater/ViewportManager.cs index b705a518ff..e4e03d1be9 100644 --- a/src/Avalonia.Controls/Repeater/ViewportManager.cs +++ b/src/Avalonia.Controls/Repeater/ViewportManager.cs @@ -340,6 +340,11 @@ namespace Avalonia.Controls // Note that the element being brought into view could be a descendant. var targetChild = GetImmediateChildOfRepeater((IControl)args.TargetObject); + if (targetChild is null) + { + return; + } + // Make sure that only the target child can be the anchor during the bring into view operation. foreach (var child in _owner.Children) { @@ -373,7 +378,7 @@ namespace Avalonia.Controls if (parent == null) { - throw new InvalidOperationException("OnBringIntoViewRequested called with args.target element not under the ItemsRepeater that recieved the call"); + return null; } return targetChild;