From dad0c4d18afc0462753b04d70bdb5b32ee6af335 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Thu, 15 Oct 2020 20:24:03 +0300 Subject: [PATCH 1/2] Fixed invalid cast issue if source isn't visual --- .../Primitives/SelectingItemsControl.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index 4317d795f1..19c2b3b8fa 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -356,17 +356,13 @@ namespace Avalonia.Controls.Primitives /// The container or null if the event did not originate in a container. protected IControl? GetContainerFromEventSource(IInteractive eventSource) { - var parent = (IVisual)eventSource; - - while (parent != null) + for (var current = eventSource as IVisual; current != null; current = current.VisualParent) { - if (parent is IControl control && control.LogicalParent == this - && ItemContainerGenerator?.IndexFromContainer(control) != -1) + if (current is IControl control && control.LogicalParent == this && + ItemContainerGenerator?.IndexFromContainer(control) != -1) { return control; } - - parent = parent.VisualParent; } return null; From 02e6a4ffa5c635f17e6eb51393f88b685599d148 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Thu, 15 Oct 2020 20:24:57 +0300 Subject: [PATCH 2/2] Fixed nullability issues --- src/Avalonia.Controls/Primitives/SelectingItemsControl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index 19c2b3b8fa..d3e7751c4e 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -354,7 +354,7 @@ namespace Avalonia.Controls.Primitives /// /// The control that raised the event. /// The container or null if the event did not originate in a container. - protected IControl? GetContainerFromEventSource(IInteractive eventSource) + protected IControl? GetContainerFromEventSource(IInteractive? eventSource) { for (var current = eventSource as IVisual; current != null; current = current.VisualParent) { @@ -666,7 +666,7 @@ namespace Avalonia.Controls.Primitives /// false. /// protected bool UpdateSelectionFromEventSource( - IInteractive eventSource, + IInteractive? eventSource, bool select = true, bool rangeModifier = false, bool toggleModifier = false,