feat: update click behavior.
This commit is contained in:
@@ -15,6 +15,8 @@ namespace Ursa.Controls;
|
||||
[TemplatePart(PartNames.PART_Popup, typeof(Popup))]
|
||||
public class TreeComboBox: SelectingItemsControl
|
||||
{
|
||||
private Popup? _popup;
|
||||
|
||||
private static readonly FuncTemplate<Panel?> DefaultPanel =
|
||||
new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
|
||||
|
||||
@@ -87,6 +89,12 @@ public class TreeComboBox: SelectingItemsControl
|
||||
FocusableProperty.OverrideDefaultValue<TreeComboBox>(true);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_popup = e.NameScope.Find<Popup>(PartNames.PART_Popup);
|
||||
}
|
||||
|
||||
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
|
||||
{
|
||||
return NeedsContainer<TreeComboBoxItem>(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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Control>(PartNames.PART_Header);
|
||||
DoubleTappedEvent.AddHandler(OnDoubleTapped, _header);
|
||||
DoubleTappedEvent.AddHandler(OnDoubleTapped, RoutingStrategies.Tunnel, true, this);
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user