feat: add new autocomplete box.

This commit is contained in:
rabbitism
2024-08-10 22:58:52 +08:00
parent 1a99b92eee
commit b58c8f071e
6 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using Avalonia.Input;
using Avalonia.Interactivity;
namespace Ursa.Controls;
public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox
{
protected override Type StyleKeyOverride { get; } = typeof(Avalonia.Controls.AutoCompleteBox);
static AutoCompleteBox()
{
MinimumPrefixLengthProperty.OverrideDefaultValue<AutoCompleteBox>(0);
}
public AutoCompleteBox()
{
this.AddHandler(PointerPressedEvent, OnBoxPointerPressed, RoutingStrategies.Tunnel);
}
private void OnBoxPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (Equals(sender, this) && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
SetCurrentValue(IsDropDownOpenProperty, true);
}
}
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
SetCurrentValue(IsDropDownOpenProperty, true);
}
}