From d1e4614a3855e1137a8dc6326c54570bee8b689b Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 30 Apr 2020 17:13:18 +0200 Subject: [PATCH] Added ComboBox.PopupClosedOverride. To control whether the event that caused the popup to close is swallowed or passed through. For now just implemented on `ComboBox` - we may want to implement it in future on all controls that display popups if this is something that proves generally useful. Fixes #3845. --- src/Avalonia.Controls/ComboBox.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index 1daa6a5630..67ef6cd1e9 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -234,6 +234,23 @@ namespace Avalonia.Controls base.OnTemplateApplied(e); } + /// + /// Called when the ComboBox popup is closed, with the + /// that caused the popup to close. + /// + /// The event args. + /// + /// This method can be overridden to control whether the event that caused the popup to close + /// is swallowed or passed through. + /// + protected virtual void PopupClosedOverride(PopupClosedEventArgs e) + { + if (e.CloseEvent is PointerEventArgs pointerEvent) + { + pointerEvent.Handled = true; + } + } + internal void ItemFocused(ComboBoxItem dropDownItem) { if (IsDropDownOpen && dropDownItem.IsFocused && dropDownItem.IsArrangeValid) @@ -247,10 +264,7 @@ namespace Avalonia.Controls _subscriptionsOnOpen?.Dispose(); _subscriptionsOnOpen = null; - if (e.CloseEvent is PointerEventArgs pointerEvent) - { - pointerEvent.Handled = true; - } + PopupClosedOverride(e); if (CanFocus(this)) {