From fa7891297bcd913abf5be6677dbb59520adf391a Mon Sep 17 00:00:00 2001 From: Dong Bin Date: Fri, 5 Sep 2025 00:01:12 +0800 Subject: [PATCH] feat: implement SelectedItems property in MultiAutoCompleteBox and remove SelectedItem property --- .../MultiAutoCompleteBox.Properties.cs | 36 ++++++------------- .../AutoCompleteBox/MultiAutoCompleteBox.cs | 10 ++++-- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.Properties.cs b/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.Properties.cs index 53eb4b2..c35c220 100644 --- a/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.Properties.cs +++ b/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.Properties.cs @@ -78,16 +78,6 @@ public partial class MultiAutoCompleteBox AvaloniaProperty.Register( nameof(IsDropDownOpen)); - /// - /// Identifies the property. - /// - /// The identifier the property. - public static readonly StyledProperty SelectedItemProperty = - AvaloniaProperty.Register( - nameof(SelectedItem), - defaultBindingMode: BindingMode.TwoWay, - enableDataValidation: true); - /// /// Identifies the property. /// @@ -182,6 +172,16 @@ public partial class MultiAutoCompleteBox /// public static readonly StyledProperty InnerRightContentProperty = TextBox.InnerRightContentProperty.AddOwner(); + + public static readonly StyledProperty SelectedItemsProperty = + AvaloniaProperty.Register( + nameof(SelectedItems)); + + public IList? SelectedItems + { + get => GetValue(SelectedItemsProperty); + set => SetValue(SelectedItemsProperty, value); + } /// /// Gets or sets the caret index @@ -316,22 +316,6 @@ public partial class MultiAutoCompleteBox } } - /// - /// Gets or sets the selected item in the drop-down. - /// - /// The selected item in the drop-down. - /// - /// If the IsTextCompletionEnabled property is true and text typed by - /// the user matches an item in the ItemsSource collection, which is - /// then displayed in the text box, the SelectedItem property will be - /// a null reference. - /// - public object? SelectedItem - { - get => GetValue(SelectedItemProperty); - set => SetValue(SelectedItemProperty, value); - } - /// /// Gets or sets the text in the text box portion of the /// control. diff --git a/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.cs b/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.cs index b263b70..958ba71 100644 --- a/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.cs +++ b/src/Ursa/Controls/AutoCompleteBox/MultiAutoCompleteBox.cs @@ -14,13 +14,14 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Threading; using Avalonia.VisualTree; +using Irihi.Avalonia.Shared.Contracts; using Irihi.Avalonia.Shared.Helpers; using Ursa.Common; namespace Ursa.Controls; -public partial class MultiAutoCompleteBox : TemplatedControl +public partial class MultiAutoCompleteBox : TemplatedControl, IInnerContentControl { /// /// Specifies the name of the selection adapter TemplatePart. @@ -181,7 +182,7 @@ public partial class MultiAutoCompleteBox : TemplatedControl MinimumPopulateDelayProperty.Changed.AddClassHandler((x, e) => x.OnMinimumPopulateDelayChanged(e)); IsDropDownOpenProperty.Changed.AddClassHandler((x, e) => x.OnIsDropDownOpenChanged(e)); - SelectedItemProperty.Changed.AddClassHandler((x, e) => x.OnSelectedItemPropertyChanged(e)); + // SelectedItemProperty.Changed.AddClassHandler((x, e) => x.OnSelectedItemPropertyChanged(e)); TextProperty.Changed.AddClassHandler((x, e) => x.OnTextPropertyChanged(e)); SearchTextProperty.Changed.AddClassHandler((x, e) => x.OnSearchTextPropertyChanged(e)); FilterModeProperty.Changed.AddClassHandler((x, e) => x.OnFilterModePropertyChanged(e)); @@ -589,7 +590,10 @@ public partial class MultiAutoCompleteBox : TemplatedControl BindingValueType state, Exception? error) { - if (property == TextProperty || property == SelectedItemProperty) DataValidationErrors.SetError(this, error); + if (property == TextProperty || property == SelectedItemProperty) + { + DataValidationErrors.SetError(this, error); + } } ///