feat: add new class inheritance mechanism.

This commit is contained in:
rabbitism
2024-08-12 13:33:27 +08:00
parent b58c8f071e
commit 74ad61515f
5 changed files with 124 additions and 16 deletions

View File

@@ -1,12 +1,15 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Contracts;
namespace Ursa.Controls;
public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox
public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox, IClearControl
{
protected override Type StyleKeyOverride { get; } = typeof(Avalonia.Controls.AutoCompleteBox);
// protected override Type StyleKeyOverride { get; } = typeof(Avalonia.Controls.AutoCompleteBox);
private TextBox? _text;
static AutoCompleteBox()
{
MinimumPrefixLengthProperty.OverrideDefaultValue<AutoCompleteBox>(0);
@@ -17,6 +20,12 @@ public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox
this.AddHandler(PointerPressedEvent, OnBoxPointerPressed, RoutingStrategies.Tunnel);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_text = e.NameScope.Get<TextBox>("PART_TextBox");
}
private void OnBoxPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (Equals(sender, this) && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
@@ -30,4 +39,9 @@ public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox
base.OnGotFocus(e);
SetCurrentValue(IsDropDownOpenProperty, true);
}
public void Clear()
{
SetCurrentValue(SelectedItemProperty, null);
}
}