diff --git a/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml b/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml index 2624e7d..171cfe8 100644 --- a/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml +++ b/demo/Ursa.Demo/Pages/TreeComboBoxDemo.axaml @@ -9,7 +9,11 @@ - + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml b/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml index db57123..01642e4 100644 --- a/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml +++ b/src/Ursa.Themes.Semi/Controls/TreeComboBox.axaml @@ -1,17 +1,19 @@ + xmlns:iri="https://irihi.tech/shared" + xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"> + + - - + + - - + @@ -28,12 +30,15 @@ - - + + - + diff --git a/src/Ursa/Controls/ComboBox/TreeComboBox.cs b/src/Ursa/Controls/ComboBox/TreeComboBox.cs index 060dfee..a20632a 100644 --- a/src/Ursa/Controls/ComboBox/TreeComboBox.cs +++ b/src/Ursa/Controls/ComboBox/TreeComboBox.cs @@ -15,6 +15,8 @@ namespace Ursa.Controls; [TemplatePart(PartNames.PART_Popup, typeof(Popup))] public class TreeComboBox: SelectingItemsControl { + private Popup? _popup; + private static readonly FuncTemplate DefaultPanel = new FuncTemplate(() => new VirtualizingStackPanel()); @@ -87,6 +89,12 @@ public class TreeComboBox: SelectingItemsControl FocusableProperty.OverrideDefaultValue(true); } + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + _popup = e.NameScope.Find(PartNames.PART_Popup); + } + protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey) { return NeedsContainer(item, out recycleKey); @@ -122,7 +130,16 @@ public class TreeComboBox: SelectingItemsControl base.OnPointerReleased(e); if (e.InitialPressMouseButton == MouseButton.Left) { - IsDropDownOpen = !IsDropDownOpen; + if (_popup is not null && _popup.IsOpen && e.Source is TextBlock v && _popup.IsInsidePopup(v)) + { + SelectionBoxItem = v.Text; + SetCurrentValue(IsDropDownOpenProperty, false); + } + else + { + IsDropDownOpen = !IsDropDownOpen; + } + } } } \ No newline at end of file diff --git a/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs b/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs index 3908c00..887d20a 100644 --- a/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs +++ b/src/Ursa/Controls/ComboBox/TreeComboBoxItem.cs @@ -3,6 +3,7 @@ using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; using Avalonia.Input; +using Avalonia.Interactivity; using Avalonia.LogicalTree; using Avalonia.Media; using Avalonia.Media.TextFormatting; @@ -47,9 +48,9 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); - DoubleTappedEvent.RemoveHandler(OnDoubleTapped, _header); + DoubleTappedEvent.RemoveHandler(OnDoubleTapped, this); _header = e.NameScope.Find(PartNames.PART_Header); - DoubleTappedEvent.AddHandler(OnDoubleTapped, _header); + DoubleTappedEvent.AddHandler(OnDoubleTapped, RoutingStrategies.Tunnel, true, this); } protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)