From 056bbdd9bd7459efcdc36ec47740f26e0617e494 Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 20:13:39 -0400 Subject: [PATCH 1/8] Switch AutoCompleteBox to use the same TextChanged event as TextBox --- src/Avalonia.Controls/AutoCompleteBox.cs | 30 +++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Avalonia.Controls/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox.cs index 8a8c4ead86..3cf7a56c58 100644 --- a/src/Avalonia.Controls/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox.cs @@ -610,6 +610,13 @@ namespace Avalonia.Controls o => o.AsyncPopulator, (o, v) => o.AsyncPopulator = v); + /// + /// Defines the event. + /// + public static readonly RoutedEvent TextChangedEvent = + RoutedEvent.Register( + nameof(TextChanged), RoutingStrategies.Bubble); + private static bool IsValidMinimumPrefixLength(int value) => value >= -1; private static bool IsValidMinimumPopulateDelay(TimeSpan value) => value.TotalMilliseconds >= 0.0; @@ -1529,10 +1536,14 @@ namespace Avalonia.Controls } /// - /// Occurs when the text in the text box portion of the - /// changes. + /// Occurs asynchronously when the text in the portion of the + /// changes. /// - public event EventHandler? TextChanged; + public event EventHandler? TextChanged + { + add => AddHandler(TextChangedEvent, value); + remove => RemoveHandler(TextChangedEvent, value); + } /// /// Occurs when the @@ -1690,15 +1701,12 @@ namespace Avalonia.Controls } /// - /// Raises the - /// - /// event. + /// Raises the event. /// - /// A - /// that contains the event data. - protected virtual void OnTextChanged(RoutedEventArgs e) + /// A that contains the event data. + protected virtual void OnTextChanged(TextChangedEventArgs e) { - TextChanged?.Invoke(this, e); + RaiseEvent(e); } /// @@ -1985,7 +1993,7 @@ namespace Avalonia.Controls if (callTextChanged) { - OnTextChanged(new RoutedEventArgs()); + OnTextChanged(new TextChangedEventArgs(TextChangedEvent)); } } From b6698825fc2d1f7c353a4a53834e07d7b4e5e90e Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 20:21:47 -0400 Subject: [PATCH 2/8] Modernize some code formatting in AutoCompleteBox --- src/Avalonia.Controls/AutoCompleteBox.cs | 82 +++++++++++------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Avalonia.Controls/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox.cs index 3cf7a56c58..e7a14bf568 100644 --- a/src/Avalonia.Controls/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox.cs @@ -898,8 +898,8 @@ namespace Avalonia.Controls /// public int MinimumPrefixLength { - get { return GetValue(MinimumPrefixLengthProperty); } - set { SetValue(MinimumPrefixLengthProperty, value); } + get => GetValue(MinimumPrefixLengthProperty); + set => SetValue(MinimumPrefixLengthProperty, value); } /// @@ -914,8 +914,8 @@ namespace Avalonia.Controls /// public bool IsTextCompletionEnabled { - get { return GetValue(IsTextCompletionEnabledProperty); } - set { SetValue(IsTextCompletionEnabledProperty, value); } + get => GetValue(IsTextCompletionEnabledProperty); + set => SetValue(IsTextCompletionEnabledProperty, value); } /// @@ -934,8 +934,8 @@ namespace Avalonia.Controls /// public IDataTemplate ItemTemplate { - get { return GetValue(ItemTemplateProperty); } - set { SetValue(ItemTemplateProperty, value); } + get => GetValue(ItemTemplateProperty); + set => SetValue(ItemTemplateProperty, value); } /// @@ -950,8 +950,8 @@ namespace Avalonia.Controls /// the list of possible matches in the drop-down. The default is 0. public TimeSpan MinimumPopulateDelay { - get { return GetValue(MinimumPopulateDelayProperty); } - set { SetValue(MinimumPopulateDelayProperty, value); } + get => GetValue(MinimumPopulateDelayProperty); + set => SetValue(MinimumPopulateDelayProperty, value); } /// @@ -964,8 +964,8 @@ namespace Avalonia.Controls /// The specified value is less than 0. public double MaxDropDownHeight { - get { return GetValue(MaxDropDownHeightProperty); } - set { SetValue(MaxDropDownHeightProperty, value); } + get => GetValue(MaxDropDownHeightProperty); + set => SetValue(MaxDropDownHeightProperty, value); } /// @@ -978,8 +978,8 @@ namespace Avalonia.Controls /// public bool IsDropDownOpen { - get { return _isDropDownOpen; } - set { SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); } + get => _isDropDownOpen; + set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); } /// @@ -993,7 +993,7 @@ namespace Avalonia.Controls [AssignBinding] public IBinding? ValueMemberBinding { - get { return _valueBindingEvaluator?.ValueBinding; } + get => _valueBindingEvaluator?.ValueBinding; set { if (ValueMemberBinding != value) @@ -1016,8 +1016,8 @@ namespace Avalonia.Controls /// public object? SelectedItem { - get { return _selectedItem; } - set { SetAndRaise(SelectedItemProperty, ref _selectedItem, value); } + get => _selectedItem; + set => SetAndRaise(SelectedItemProperty, ref _selectedItem, value); } /// @@ -1028,8 +1028,8 @@ namespace Avalonia.Controls /// control. public string? Text { - get { return _text; } - set { SetAndRaise(TextProperty, ref _text, value); } + get => _text; + set => SetAndRaise(TextProperty, ref _text, value); } /// @@ -1047,7 +1047,7 @@ namespace Avalonia.Controls /// public string? SearchText { - get { return _searchText; } + get => _searchText; private set { try @@ -1083,14 +1083,14 @@ namespace Avalonia.Controls /// public AutoCompleteFilterMode FilterMode { - get { return GetValue(FilterModeProperty); } - set { SetValue(FilterModeProperty, value); } + get => GetValue(FilterModeProperty); + set => SetValue(FilterModeProperty, value); } public string? Watermark { - get { return GetValue(WatermarkProperty); } - set { SetValue(WatermarkProperty, value); } + get => GetValue(WatermarkProperty); + set => SetValue(WatermarkProperty, value); } /// @@ -1109,8 +1109,8 @@ namespace Avalonia.Controls /// public AutoCompleteFilterPredicate? ItemFilter { - get { return _itemFilter; } - set { SetAndRaise(ItemFilterProperty, ref _itemFilter, value); } + get => _itemFilter; + set => SetAndRaise(ItemFilterProperty, ref _itemFilter, value); } /// @@ -1129,8 +1129,8 @@ namespace Avalonia.Controls /// public AutoCompleteFilterPredicate? TextFilter { - get { return _textFilter; } - set { SetAndRaise(TextFilterProperty, ref _textFilter, value); } + get => _textFilter; + set => SetAndRaise(TextFilterProperty, ref _textFilter, value); } /// @@ -1145,8 +1145,8 @@ namespace Avalonia.Controls /// public AutoCompleteSelector? ItemSelector { - get { return _itemSelector; } - set { SetAndRaise(ItemSelectorProperty, ref _itemSelector, value); } + get => _itemSelector; + set => SetAndRaise(ItemSelectorProperty, ref _itemSelector, value); } /// @@ -1163,14 +1163,14 @@ namespace Avalonia.Controls /// public AutoCompleteSelector? TextSelector { - get { return _textSelector; } - set { SetAndRaise(TextSelectorProperty, ref _textSelector, value); } + get => _textSelector; + set => SetAndRaise(TextSelectorProperty, ref _textSelector, value); } public Func>>? AsyncPopulator { - get { return _asyncPopulator; } - set { SetAndRaise(AsyncPopulatorProperty, ref _asyncPopulator, value); } + get => _asyncPopulator; + set => SetAndRaise(AsyncPopulatorProperty, ref _asyncPopulator, value); } /// @@ -1183,8 +1183,8 @@ namespace Avalonia.Controls /// control. public IEnumerable? Items { - get { return _itemsEnumerable; } - set { SetAndRaise(ItemsProperty, ref _itemsEnumerable, value); } + get => _itemsEnumerable; + set => SetAndRaise(ItemsProperty, ref _itemsEnumerable, value); } /// @@ -1197,7 +1197,7 @@ namespace Avalonia.Controls /// private TextBox? TextBox { - get { return _textBox; } + get => _textBox; set { _textBoxSubscriptions?.Dispose(); @@ -1261,7 +1261,7 @@ namespace Avalonia.Controls /// protected ISelectionAdapter? SelectionAdapter { - get { return _adapter; } + get => _adapter; set { if (_adapter != null) @@ -2748,8 +2748,6 @@ namespace Avalonia.Controls /// private IBinding? _binding; - #region public T Value - /// /// Identifies the Value dependency property. /// @@ -2761,18 +2759,16 @@ namespace Avalonia.Controls /// public T Value { - get { return GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } + get => GetValue(ValueProperty); + set => SetValue(ValueProperty, value); } - #endregion public string Value - /// /// Gets or sets the value binding. /// public IBinding? ValueBinding { - get { return _binding; } + get => _binding; set { _binding = value; From bbb49ab1591920d4d7d45b500be7062048c0c06d Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 20:22:39 -0400 Subject: [PATCH 3/8] Move AutoCompleteBox into its own directory --- src/Avalonia.Controls/{ => AutoCompleteBox}/AutoCompleteBox.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Avalonia.Controls/{ => AutoCompleteBox}/AutoCompleteBox.cs (100%) diff --git a/src/Avalonia.Controls/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs similarity index 100% rename from src/Avalonia.Controls/AutoCompleteBox.cs rename to src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs From a28bf0f5af438319910182a94b8736514e528db9 Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 20:32:12 -0400 Subject: [PATCH 4/8] Split apart AutoCompleteBox into multiple files --- .../AutoCompleteBox/AutoCompleteBox.cs | 185 ------------------ .../AutoCompleteBox/AutoCompleteFilterMode.cs | 133 +++++++++++++ .../AutoCompleteBox/PopulatedEventArgs.cs | 39 ++++ .../AutoCompleteBox/PopulatingEventArgs.cs | 39 ++++ 4 files changed, 211 insertions(+), 185 deletions(-) create mode 100644 src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs create mode 100644 src/Avalonia.Controls/AutoCompleteBox/PopulatedEventArgs.cs create mode 100644 src/Avalonia.Controls/AutoCompleteBox/PopulatingEventArgs.cs diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs index e7a14bf568..608d18d0d3 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs @@ -26,65 +26,6 @@ using Avalonia.VisualTree; namespace Avalonia.Controls { - /// - /// Provides data for the - /// - /// event. - /// - public class PopulatedEventArgs : EventArgs - { - /// - /// Gets the list of possible matches added to the drop-down portion of - /// the - /// control. - /// - /// The list of possible matches added to the - /// . - public IEnumerable Data { get; private set; } - - /// - /// Initializes a new instance of the - /// . - /// - /// The list of possible matches added to the - /// drop-down portion of the - /// control. - public PopulatedEventArgs(IEnumerable data) - { - Data = data; - } - } - - /// - /// Provides data for the - /// - /// event. - /// - public class PopulatingEventArgs : CancelEventArgs - { - /// - /// Gets the text that is used to determine which items to display in - /// the - /// control. - /// - /// The text that is used to determine which items to display in - /// the . - public string? Parameter { get; private set; } - - /// - /// Initializes a new instance of the - /// . - /// - /// The value of the - /// - /// property, which is used to filter items for the - /// control. - public PopulatingEventArgs(string? parameter) - { - Parameter = parameter; - } - } - /// /// Represents the filter used by the /// control to @@ -100,132 +41,6 @@ namespace Avalonia.Controls /// be either a string or an object. public delegate bool AutoCompleteFilterPredicate(string? search, T item); - /// - /// Specifies how text in the text box portion of the - /// control is used - /// to filter items specified by the - /// - /// property for display in the drop-down. - /// - public enum AutoCompleteFilterMode - { - /// - /// Specifies that no filter is used. All items are returned. - /// - None = 0, - - /// - /// Specifies a culture-sensitive, case-insensitive filter where the - /// returned items start with the specified text. The filter uses the - /// - /// method, specifying - /// as - /// the string comparison criteria. - /// - StartsWith = 1, - - /// - /// Specifies a culture-sensitive, case-sensitive filter where the - /// returned items start with the specified text. The filter uses the - /// - /// method, specifying - /// as the string - /// comparison criteria. - /// - StartsWithCaseSensitive = 2, - - /// - /// Specifies an ordinal, case-insensitive filter where the returned - /// items start with the specified text. The filter uses the - /// - /// method, specifying - /// as the - /// string comparison criteria. - /// - StartsWithOrdinal = 3, - - /// - /// Specifies an ordinal, case-sensitive filter where the returned items - /// start with the specified text. The filter uses the - /// - /// method, specifying as - /// the string comparison criteria. - /// - StartsWithOrdinalCaseSensitive = 4, - - /// - /// Specifies a culture-sensitive, case-insensitive filter where the - /// returned items contain the specified text. - /// - Contains = 5, - - /// - /// Specifies a culture-sensitive, case-sensitive filter where the - /// returned items contain the specified text. - /// - ContainsCaseSensitive = 6, - - /// - /// Specifies an ordinal, case-insensitive filter where the returned - /// items contain the specified text. - /// - ContainsOrdinal = 7, - - /// - /// Specifies an ordinal, case-sensitive filter where the returned items - /// contain the specified text. - /// - ContainsOrdinalCaseSensitive = 8, - - /// - /// Specifies a culture-sensitive, case-insensitive filter where the - /// returned items equal the specified text. The filter uses the - /// - /// method, specifying - /// as - /// the search comparison criteria. - /// - Equals = 9, - - /// - /// Specifies a culture-sensitive, case-sensitive filter where the - /// returned items equal the specified text. The filter uses the - /// - /// method, specifying - /// as the string - /// comparison criteria. - /// - EqualsCaseSensitive = 10, - - /// - /// Specifies an ordinal, case-insensitive filter where the returned - /// items equal the specified text. The filter uses the - /// - /// method, specifying - /// as the - /// string comparison criteria. - /// - EqualsOrdinal = 11, - - /// - /// Specifies an ordinal, case-sensitive filter where the returned items - /// equal the specified text. The filter uses the - /// - /// method, specifying as - /// the string comparison criteria. - /// - EqualsOrdinalCaseSensitive = 12, - - /// - /// Specifies that a custom filter is used. This mode is used when the - /// - /// or - /// - /// properties are set. - /// - Custom = 13, - } - /// /// Represents the selector used by the /// control to diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs new file mode 100644 index 0000000000..9aea49aef3 --- /dev/null +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs @@ -0,0 +1,133 @@ +// (c) Copyright Microsoft Corporation. +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details. +// All other rights reserved. + +namespace Avalonia.Controls +{ + /// + /// Specifies how text in the text box portion of the + /// control is used + /// to filter items specified by the + /// + /// property for display in the drop-down. + /// + public enum AutoCompleteFilterMode + { + /// + /// Specifies that no filter is used. All items are returned. + /// + None = 0, + + /// + /// Specifies a culture-sensitive, case-insensitive filter where the + /// returned items start with the specified text. The filter uses the + /// + /// method, specifying + /// as + /// the string comparison criteria. + /// + StartsWith = 1, + + /// + /// Specifies a culture-sensitive, case-sensitive filter where the + /// returned items start with the specified text. The filter uses the + /// + /// method, specifying + /// as the string + /// comparison criteria. + /// + StartsWithCaseSensitive = 2, + + /// + /// Specifies an ordinal, case-insensitive filter where the returned + /// items start with the specified text. The filter uses the + /// + /// method, specifying + /// as the + /// string comparison criteria. + /// + StartsWithOrdinal = 3, + + /// + /// Specifies an ordinal, case-sensitive filter where the returned items + /// start with the specified text. The filter uses the + /// + /// method, specifying as + /// the string comparison criteria. + /// + StartsWithOrdinalCaseSensitive = 4, + + /// + /// Specifies a culture-sensitive, case-insensitive filter where the + /// returned items contain the specified text. + /// + Contains = 5, + + /// + /// Specifies a culture-sensitive, case-sensitive filter where the + /// returned items contain the specified text. + /// + ContainsCaseSensitive = 6, + + /// + /// Specifies an ordinal, case-insensitive filter where the returned + /// items contain the specified text. + /// + ContainsOrdinal = 7, + + /// + /// Specifies an ordinal, case-sensitive filter where the returned items + /// contain the specified text. + /// + ContainsOrdinalCaseSensitive = 8, + + /// + /// Specifies a culture-sensitive, case-insensitive filter where the + /// returned items equal the specified text. The filter uses the + /// + /// method, specifying + /// as + /// the search comparison criteria. + /// + Equals = 9, + + /// + /// Specifies a culture-sensitive, case-sensitive filter where the + /// returned items equal the specified text. The filter uses the + /// + /// method, specifying + /// as the string + /// comparison criteria. + /// + EqualsCaseSensitive = 10, + + /// + /// Specifies an ordinal, case-insensitive filter where the returned + /// items equal the specified text. The filter uses the + /// + /// method, specifying + /// as the + /// string comparison criteria. + /// + EqualsOrdinal = 11, + + /// + /// Specifies an ordinal, case-sensitive filter where the returned items + /// equal the specified text. The filter uses the + /// + /// method, specifying as + /// the string comparison criteria. + /// + EqualsOrdinalCaseSensitive = 12, + + /// + /// Specifies that a custom filter is used. This mode is used when the + /// + /// or + /// + /// properties are set. + /// + Custom = 13, + } +} diff --git a/src/Avalonia.Controls/AutoCompleteBox/PopulatedEventArgs.cs b/src/Avalonia.Controls/AutoCompleteBox/PopulatedEventArgs.cs new file mode 100644 index 0000000000..22bc1d3cab --- /dev/null +++ b/src/Avalonia.Controls/AutoCompleteBox/PopulatedEventArgs.cs @@ -0,0 +1,39 @@ +// (c) Copyright Microsoft Corporation. +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details. +// All other rights reserved. + +using System; +using System.Collections; + +namespace Avalonia.Controls +{ + /// + /// Provides data for the + /// + /// event. + /// + public class PopulatedEventArgs : EventArgs + { + /// + /// Gets the list of possible matches added to the drop-down portion of + /// the + /// control. + /// + /// The list of possible matches added to the + /// . + public IEnumerable Data { get; private set; } + + /// + /// Initializes a new instance of the + /// . + /// + /// The list of possible matches added to the + /// drop-down portion of the + /// control. + public PopulatedEventArgs(IEnumerable data) + { + Data = data; + } + } +} diff --git a/src/Avalonia.Controls/AutoCompleteBox/PopulatingEventArgs.cs b/src/Avalonia.Controls/AutoCompleteBox/PopulatingEventArgs.cs new file mode 100644 index 0000000000..c4941ad6fe --- /dev/null +++ b/src/Avalonia.Controls/AutoCompleteBox/PopulatingEventArgs.cs @@ -0,0 +1,39 @@ +// (c) Copyright Microsoft Corporation. +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details. +// All other rights reserved. + +using System.ComponentModel; + +namespace Avalonia.Controls +{ + /// + /// Provides data for the + /// + /// event. + /// + public class PopulatingEventArgs : CancelEventArgs + { + /// + /// Gets the text that is used to determine which items to display in + /// the + /// control. + /// + /// The text that is used to determine which items to display in + /// the . + public string? Parameter { get; private set; } + + /// + /// Initializes a new instance of the + /// . + /// + /// The value of the + /// + /// property, which is used to filter items for the + /// control. + public PopulatingEventArgs(string? parameter) + { + Parameter = parameter; + } + } +} From d86cb35d3b815b90c5f3410f97576ed5f5e2ef2d Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 20:38:31 -0400 Subject: [PATCH 5/8] Separate out public AutoCompleteBox properties --- .../AutoCompleteBox.Properties.cs | 540 ++++++++++++++++++ .../AutoCompleteBox/AutoCompleteBox.cs | 533 +---------------- 2 files changed, 549 insertions(+), 524 deletions(-) create mode 100644 src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs new file mode 100644 index 0000000000..4f70f8271e --- /dev/null +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs @@ -0,0 +1,540 @@ +// (c) Copyright Microsoft Corporation. +// This source is subject to the Microsoft Public License (Ms-PL). +// Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details. +// All other rights reserved. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Avalonia.Controls.Templates; +using Avalonia.Data; + +namespace Avalonia.Controls +{ + public partial class AutoCompleteBox + { + public static readonly StyledProperty WatermarkProperty = + TextBox.WatermarkProperty.AddOwner(); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly StyledProperty MinimumPrefixLengthProperty = + AvaloniaProperty.Register( + nameof(MinimumPrefixLength), 1, + validate: IsValidMinimumPrefixLength); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly StyledProperty MinimumPopulateDelayProperty = + AvaloniaProperty.Register( + nameof(MinimumPopulateDelay), + TimeSpan.Zero, + validate: IsValidMinimumPopulateDelay); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly StyledProperty MaxDropDownHeightProperty = + AvaloniaProperty.Register( + nameof(MaxDropDownHeight), + double.PositiveInfinity, + validate: IsValidMaxDropDownHeight); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly StyledProperty IsTextCompletionEnabledProperty = + AvaloniaProperty.Register(nameof(IsTextCompletionEnabled)); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly StyledProperty ItemTemplateProperty = + AvaloniaProperty.Register(nameof(ItemTemplate)); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty IsDropDownOpenProperty = + AvaloniaProperty.RegisterDirect( + nameof(IsDropDownOpen), + o => o.IsDropDownOpen, + (o, v) => o.IsDropDownOpen = v); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier the + /// + /// dependency property. + public static readonly DirectProperty SelectedItemProperty = + AvaloniaProperty.RegisterDirect( + nameof(SelectedItem), + o => o.SelectedItem, + (o, v) => o.SelectedItem = v, + defaultBindingMode: BindingMode.TwoWay, + enableDataValidation: true); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty TextProperty = + TextBlock.TextProperty.AddOwnerWithDataValidation( + o => o.Text, + (o, v) => o.Text = v, + defaultBindingMode: BindingMode.TwoWay, + enableDataValidation: true); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty SearchTextProperty = + AvaloniaProperty.RegisterDirect( + nameof(SearchText), + o => o.SearchText, + unsetValue: string.Empty); + + /// + /// Gets the identifier for the + /// + /// dependency property. + /// + public static readonly StyledProperty FilterModeProperty = + AvaloniaProperty.Register( + nameof(FilterMode), + defaultValue: AutoCompleteFilterMode.StartsWith, + validate: IsValidFilterMode); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty?> ItemFilterProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(ItemFilter), + o => o.ItemFilter, + (o, v) => o.ItemFilter = v); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty?> TextFilterProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(TextFilter), + o => o.TextFilter, + (o, v) => o.TextFilter = v, + unsetValue: AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith)); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty?> ItemSelectorProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(ItemSelector), + o => o.ItemSelector, + (o, v) => o.ItemSelector = v); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty?> TextSelectorProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(TextSelector), + o => o.TextSelector, + (o, v) => o.TextSelector = v); + + /// + /// Identifies the + /// + /// dependency property. + /// + /// The identifier for the + /// + /// dependency property. + public static readonly DirectProperty ItemsProperty = + AvaloniaProperty.RegisterDirect( + nameof(Items), + o => o.Items, + (o, v) => o.Items = v); + + public static readonly DirectProperty>>?> AsyncPopulatorProperty = + AvaloniaProperty.RegisterDirect>>?>( + nameof(AsyncPopulator), + o => o.AsyncPopulator, + (o, v) => o.AsyncPopulator = v); + + /// + /// Gets or sets the minimum number of characters required to be entered + /// in the text box before the + /// displays + /// possible matches. + /// matches. + /// + /// + /// The minimum number of characters to be entered in the text box + /// before the + /// displays possible matches. The default is 1. + /// + /// + /// If you set MinimumPrefixLength to -1, the AutoCompleteBox will + /// not provide possible matches. There is no maximum value, but + /// setting MinimumPrefixLength to value that is too large will + /// prevent the AutoCompleteBox from providing possible matches as well. + /// + public int MinimumPrefixLength + { + get => GetValue(MinimumPrefixLengthProperty); + set => SetValue(MinimumPrefixLengthProperty, value); + } + + /// + /// Gets or sets a value indicating whether the first possible match + /// found during the filtering process will be displayed automatically + /// in the text box. + /// + /// + /// True if the first possible match found will be displayed + /// automatically in the text box; otherwise, false. The default is + /// false. + /// + public bool IsTextCompletionEnabled + { + get => GetValue(IsTextCompletionEnabledProperty); + set => SetValue(IsTextCompletionEnabledProperty, value); + } + + /// + /// Gets or sets the used + /// to display each item in the drop-down portion of the control. + /// + /// The used to + /// display each item in the drop-down. The default is null. + /// + /// You use the ItemTemplate property to specify the visualization + /// of the data objects in the drop-down portion of the AutoCompleteBox + /// control. If your AutoCompleteBox is bound to a collection and you + /// do not provide specific display instructions by using a + /// DataTemplate, the resulting UI of each item is a string + /// representation of each object in the underlying collection. + /// + public IDataTemplate ItemTemplate + { + get => GetValue(ItemTemplateProperty); + set => SetValue(ItemTemplateProperty, value); + } + + /// + /// Gets or sets the minimum delay, after text is typed + /// in the text box before the + /// control + /// populates the list of possible matches in the drop-down. + /// + /// The minimum delay, after text is typed in + /// the text box, but before the + /// populates + /// the list of possible matches in the drop-down. The default is 0. + public TimeSpan MinimumPopulateDelay + { + get => GetValue(MinimumPopulateDelayProperty); + set => SetValue(MinimumPopulateDelayProperty, value); + } + + /// + /// Gets or sets the maximum height of the drop-down portion of the + /// control. + /// + /// The maximum height of the drop-down portion of the + /// control. + /// The default is . + /// The specified value is less than 0. + public double MaxDropDownHeight + { + get => GetValue(MaxDropDownHeightProperty); + set => SetValue(MaxDropDownHeightProperty, value); + } + + /// + /// Gets or sets a value indicating whether the drop-down portion of + /// the control is open. + /// + /// + /// True if the drop-down is open; otherwise, false. The default is + /// false. + /// + public bool IsDropDownOpen + { + get => _isDropDownOpen; + set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); + } + + /// + /// Gets or sets the that + /// is used to get the values for display in the text portion of + /// the + /// control. + /// + /// The object used + /// when binding to a collection property. + [AssignBinding] + public IBinding? ValueMemberBinding + { + get => _valueBindingEvaluator?.ValueBinding; + set + { + if (ValueMemberBinding != value) + { + _valueBindingEvaluator = new BindingEvaluator(value); + OnValueMemberBindingChanged(value); + } + } + } + + /// + /// 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 => _selectedItem; + set => SetAndRaise(SelectedItemProperty, ref _selectedItem, value); + } + + /// + /// Gets or sets the text in the text box portion of the + /// control. + /// + /// The text in the text box portion of the + /// control. + public string? Text + { + get => _text; + set => SetAndRaise(TextProperty, ref _text, value); + } + + /// + /// Gets the text that is used to filter items in the + /// + /// item collection. + /// + /// The text that is used to filter items in the + /// + /// item collection. + /// + /// The SearchText value is typically the same as the + /// Text property, but is set after the TextChanged event occurs + /// and before the Populating event. + /// + public string? SearchText + { + get => _searchText; + private set + { + try + { + _allowWrite = true; + SetAndRaise(SearchTextProperty, ref _searchText, value); + } + finally + { + _allowWrite = false; + } + } + } + + /// + /// Gets or sets how the text in the text box is used to filter items + /// specified by the + /// + /// property for display in the drop-down. + /// + /// One of the + /// + /// values The default is + /// . + /// The specified value is + /// not a valid + /// . + /// + /// Use the FilterMode property to specify how possible matches are + /// filtered. For example, possible matches can be filtered in a + /// predefined or custom way. The search mode is automatically set to + /// Custom if you set the ItemFilter property. + /// + public AutoCompleteFilterMode FilterMode + { + get => GetValue(FilterModeProperty); + set => SetValue(FilterModeProperty, value); + } + + public string? Watermark + { + get => GetValue(WatermarkProperty); + set => SetValue(WatermarkProperty, value); + } + + /// + /// Gets or sets the custom method that uses user-entered text to filter + /// the items specified by the + /// + /// property for display in the drop-down. + /// + /// The custom method that uses the user-entered text to filter + /// the items specified by the + /// + /// property. The default is null. + /// + /// The filter mode is automatically set to Custom if you set the + /// ItemFilter property. + /// + public AutoCompleteFilterPredicate? ItemFilter + { + get => _itemFilter; + set => SetAndRaise(ItemFilterProperty, ref _itemFilter, value); + } + + /// + /// Gets or sets the custom method that uses the user-entered text to + /// filter items specified by the + /// + /// property in a text-based way for display in the drop-down. + /// + /// The custom method that uses the user-entered text to filter + /// items specified by the + /// + /// property in a text-based way for display in the drop-down. + /// + /// The search mode is automatically set to Custom if you set the + /// TextFilter property. + /// + public AutoCompleteFilterPredicate? TextFilter + { + get => _textFilter; + set => SetAndRaise(TextFilterProperty, ref _textFilter, value); + } + + /// + /// Gets or sets the custom method that combines the user-entered + /// text and one of the items specified by the + /// . + /// + /// + /// The custom method that combines the user-entered + /// text and one of the items specified by the + /// . + /// + public AutoCompleteSelector? ItemSelector + { + get => _itemSelector; + set => SetAndRaise(ItemSelectorProperty, ref _itemSelector, value); + } + + /// + /// Gets or sets the custom method that combines the user-entered + /// text and one of the items specified by the + /// + /// in a text-based way. + /// + /// + /// The custom method that combines the user-entered + /// text and one of the items specified by the + /// + /// in a text-based way. + /// + public AutoCompleteSelector? TextSelector + { + get => _textSelector; + set => SetAndRaise(TextSelectorProperty, ref _textSelector, value); + } + + public Func>>? AsyncPopulator + { + get => _asyncPopulator; + set => SetAndRaise(AsyncPopulatorProperty, ref _asyncPopulator, value); + } + + /// + /// Gets or sets a collection that is used to generate the items for the + /// drop-down portion of the + /// control. + /// + /// The collection that is used to generate the items of the + /// drop-down portion of the + /// control. + public IEnumerable? Items + { + get => _itemsEnumerable; + set => SetAndRaise(ItemsProperty, ref _itemsEnumerable, value); + } + } +} diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs index 608d18d0d3..a027b8b650 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs @@ -72,7 +72,7 @@ namespace Avalonia.Controls [TemplatePart(ElementSelectionAdapter, typeof(ISelectionAdapter))] [TemplatePart(ElementTextBox, typeof(TextBox))] [PseudoClasses(":dropdownopen")] - public class AutoCompleteBox : TemplatedControl + public partial class AutoCompleteBox : TemplatedControl { /// /// Specifies the name of the selection adapter TemplatePart. @@ -209,228 +209,22 @@ namespace Avalonia.Controls private readonly EventHandler _populateDropDownHandler; - public static readonly RoutedEvent SelectionChangedEvent = - RoutedEvent.Register(nameof(SelectionChanged), RoutingStrategies.Bubble, typeof(AutoCompleteBox)); - - public static readonly StyledProperty WatermarkProperty = - TextBox.WatermarkProperty.AddOwner(); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly StyledProperty MinimumPrefixLengthProperty = - AvaloniaProperty.Register( - nameof(MinimumPrefixLength), 1, - validate: IsValidMinimumPrefixLength); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly StyledProperty MinimumPopulateDelayProperty = - AvaloniaProperty.Register( - nameof(MinimumPopulateDelay), - TimeSpan.Zero, - validate: IsValidMinimumPopulateDelay); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly StyledProperty MaxDropDownHeightProperty = - AvaloniaProperty.Register( - nameof(MaxDropDownHeight), - double.PositiveInfinity, - validate: IsValidMaxDropDownHeight); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly StyledProperty IsTextCompletionEnabledProperty = - AvaloniaProperty.Register(nameof(IsTextCompletionEnabled)); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly StyledProperty ItemTemplateProperty = - AvaloniaProperty.Register(nameof(ItemTemplate)); - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty IsDropDownOpenProperty = - AvaloniaProperty.RegisterDirect( - nameof(IsDropDownOpen), - o => o.IsDropDownOpen, - (o, v) => o.IsDropDownOpen = v); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier the - /// - /// dependency property. - public static readonly DirectProperty SelectedItemProperty = - AvaloniaProperty.RegisterDirect( - nameof(SelectedItem), - o => o.SelectedItem, - (o, v) => o.SelectedItem = v, - defaultBindingMode: BindingMode.TwoWay, - enableDataValidation: true); - - /// - /// Identifies the - /// - /// dependency property. + /// /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty TextProperty = - TextBlock.TextProperty.AddOwnerWithDataValidation( - o => o.Text, - (o, v) => o.Text = v, - defaultBindingMode: BindingMode.TwoWay, - enableDataValidation: true); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty SearchTextProperty = - AvaloniaProperty.RegisterDirect( - nameof(SearchText), - o => o.SearchText, - unsetValue: string.Empty); - - /// - /// Gets the identifier for the - /// - /// dependency property. - /// - public static readonly StyledProperty FilterModeProperty = - AvaloniaProperty.Register( - nameof(FilterMode), - defaultValue: AutoCompleteFilterMode.StartsWith, - validate: IsValidFilterMode); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty?> ItemFilterProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(ItemFilter), - o => o.ItemFilter, - (o, v) => o.ItemFilter = v); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty?> TextFilterProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(TextFilter), - o => o.TextFilter, - (o, v) => o.TextFilter = v, - unsetValue: AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith)); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty?> ItemSelectorProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(ItemSelector), - o => o.ItemSelector, - (o, v) => o.ItemSelector = v); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty?> TextSelectorProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(TextSelector), - o => o.TextSelector, - (o, v) => o.TextSelector = v); - - /// - /// Identifies the - /// - /// dependency property. - /// - /// The identifier for the - /// - /// dependency property. - public static readonly DirectProperty ItemsProperty = - AvaloniaProperty.RegisterDirect( - nameof(Items), - o => o.Items, - (o, v) => o.Items = v); - - public static readonly DirectProperty>>?> AsyncPopulatorProperty = - AvaloniaProperty.RegisterDirect>>?>( - nameof(AsyncPopulator), - o => o.AsyncPopulator, - (o, v) => o.AsyncPopulator = v); + public static readonly RoutedEvent SelectionChangedEvent = + RoutedEvent.Register( + nameof(SelectionChanged), + RoutingStrategies.Bubble, + typeof(AutoCompleteBox)); /// /// Defines the event. /// public static readonly RoutedEvent TextChangedEvent = RoutedEvent.Register( - nameof(TextChanged), RoutingStrategies.Bubble); + nameof(TextChanged), + RoutingStrategies.Bubble); private static bool IsValidMinimumPrefixLength(int value) => value >= -1; @@ -693,315 +487,6 @@ namespace Avalonia.Controls ClearView(); } - /// - /// Gets or sets the minimum number of characters required to be entered - /// in the text box before the - /// displays - /// possible matches. - /// matches. - /// - /// - /// The minimum number of characters to be entered in the text box - /// before the - /// displays possible matches. The default is 1. - /// - /// - /// If you set MinimumPrefixLength to -1, the AutoCompleteBox will - /// not provide possible matches. There is no maximum value, but - /// setting MinimumPrefixLength to value that is too large will - /// prevent the AutoCompleteBox from providing possible matches as well. - /// - public int MinimumPrefixLength - { - get => GetValue(MinimumPrefixLengthProperty); - set => SetValue(MinimumPrefixLengthProperty, value); - } - - /// - /// Gets or sets a value indicating whether the first possible match - /// found during the filtering process will be displayed automatically - /// in the text box. - /// - /// - /// True if the first possible match found will be displayed - /// automatically in the text box; otherwise, false. The default is - /// false. - /// - public bool IsTextCompletionEnabled - { - get => GetValue(IsTextCompletionEnabledProperty); - set => SetValue(IsTextCompletionEnabledProperty, value); - } - - /// - /// Gets or sets the used - /// to display each item in the drop-down portion of the control. - /// - /// The used to - /// display each item in the drop-down. The default is null. - /// - /// You use the ItemTemplate property to specify the visualization - /// of the data objects in the drop-down portion of the AutoCompleteBox - /// control. If your AutoCompleteBox is bound to a collection and you - /// do not provide specific display instructions by using a - /// DataTemplate, the resulting UI of each item is a string - /// representation of each object in the underlying collection. - /// - public IDataTemplate ItemTemplate - { - get => GetValue(ItemTemplateProperty); - set => SetValue(ItemTemplateProperty, value); - } - - /// - /// Gets or sets the minimum delay, after text is typed - /// in the text box before the - /// control - /// populates the list of possible matches in the drop-down. - /// - /// The minimum delay, after text is typed in - /// the text box, but before the - /// populates - /// the list of possible matches in the drop-down. The default is 0. - public TimeSpan MinimumPopulateDelay - { - get => GetValue(MinimumPopulateDelayProperty); - set => SetValue(MinimumPopulateDelayProperty, value); - } - - /// - /// Gets or sets the maximum height of the drop-down portion of the - /// control. - /// - /// The maximum height of the drop-down portion of the - /// control. - /// The default is . - /// The specified value is less than 0. - public double MaxDropDownHeight - { - get => GetValue(MaxDropDownHeightProperty); - set => SetValue(MaxDropDownHeightProperty, value); - } - - /// - /// Gets or sets a value indicating whether the drop-down portion of - /// the control is open. - /// - /// - /// True if the drop-down is open; otherwise, false. The default is - /// false. - /// - public bool IsDropDownOpen - { - get => _isDropDownOpen; - set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); - } - - /// - /// Gets or sets the that - /// is used to get the values for display in the text portion of - /// the - /// control. - /// - /// The object used - /// when binding to a collection property. - [AssignBinding] - public IBinding? ValueMemberBinding - { - get => _valueBindingEvaluator?.ValueBinding; - set - { - if (ValueMemberBinding != value) - { - _valueBindingEvaluator = new BindingEvaluator(value); - OnValueMemberBindingChanged(value); - } - } - } - - /// - /// 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 => _selectedItem; - set => SetAndRaise(SelectedItemProperty, ref _selectedItem, value); - } - - /// - /// Gets or sets the text in the text box portion of the - /// control. - /// - /// The text in the text box portion of the - /// control. - public string? Text - { - get => _text; - set => SetAndRaise(TextProperty, ref _text, value); - } - - /// - /// Gets the text that is used to filter items in the - /// - /// item collection. - /// - /// The text that is used to filter items in the - /// - /// item collection. - /// - /// The SearchText value is typically the same as the - /// Text property, but is set after the TextChanged event occurs - /// and before the Populating event. - /// - public string? SearchText - { - get => _searchText; - private set - { - try - { - _allowWrite = true; - SetAndRaise(SearchTextProperty, ref _searchText, value); - } - finally - { - _allowWrite = false; - } - } - } - - /// - /// Gets or sets how the text in the text box is used to filter items - /// specified by the - /// - /// property for display in the drop-down. - /// - /// One of the - /// - /// values The default is - /// . - /// The specified value is - /// not a valid - /// . - /// - /// Use the FilterMode property to specify how possible matches are - /// filtered. For example, possible matches can be filtered in a - /// predefined or custom way. The search mode is automatically set to - /// Custom if you set the ItemFilter property. - /// - public AutoCompleteFilterMode FilterMode - { - get => GetValue(FilterModeProperty); - set => SetValue(FilterModeProperty, value); - } - - public string? Watermark - { - get => GetValue(WatermarkProperty); - set => SetValue(WatermarkProperty, value); - } - - /// - /// Gets or sets the custom method that uses user-entered text to filter - /// the items specified by the - /// - /// property for display in the drop-down. - /// - /// The custom method that uses the user-entered text to filter - /// the items specified by the - /// - /// property. The default is null. - /// - /// The filter mode is automatically set to Custom if you set the - /// ItemFilter property. - /// - public AutoCompleteFilterPredicate? ItemFilter - { - get => _itemFilter; - set => SetAndRaise(ItemFilterProperty, ref _itemFilter, value); - } - - /// - /// Gets or sets the custom method that uses the user-entered text to - /// filter items specified by the - /// - /// property in a text-based way for display in the drop-down. - /// - /// The custom method that uses the user-entered text to filter - /// items specified by the - /// - /// property in a text-based way for display in the drop-down. - /// - /// The search mode is automatically set to Custom if you set the - /// TextFilter property. - /// - public AutoCompleteFilterPredicate? TextFilter - { - get => _textFilter; - set => SetAndRaise(TextFilterProperty, ref _textFilter, value); - } - - /// - /// Gets or sets the custom method that combines the user-entered - /// text and one of the items specified by the - /// . - /// - /// - /// The custom method that combines the user-entered - /// text and one of the items specified by the - /// . - /// - public AutoCompleteSelector? ItemSelector - { - get => _itemSelector; - set => SetAndRaise(ItemSelectorProperty, ref _itemSelector, value); - } - - /// - /// Gets or sets the custom method that combines the user-entered - /// text and one of the items specified by the - /// - /// in a text-based way. - /// - /// - /// The custom method that combines the user-entered - /// text and one of the items specified by the - /// - /// in a text-based way. - /// - public AutoCompleteSelector? TextSelector - { - get => _textSelector; - set => SetAndRaise(TextSelectorProperty, ref _textSelector, value); - } - - public Func>>? AsyncPopulator - { - get => _asyncPopulator; - set => SetAndRaise(AsyncPopulatorProperty, ref _asyncPopulator, value); - } - - /// - /// Gets or sets a collection that is used to generate the items for the - /// drop-down portion of the - /// control. - /// - /// The collection that is used to generate the items of the - /// drop-down portion of the - /// control. - public IEnumerable? Items - { - get => _itemsEnumerable; - set => SetAndRaise(ItemsProperty, ref _itemsEnumerable, value); - } - /// /// Gets or sets the drop down popup control. /// From 62b1eea00c3880bb324207ad3b6dec60da624ead Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 20:48:02 -0400 Subject: [PATCH 6/8] Cleanup some AutoCompleteBox property comments --- .../AutoCompleteBox.Properties.cs | 187 ++++++------------ 1 file changed, 55 insertions(+), 132 deletions(-) diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs index 4f70f8271e..ecbe01d8b7 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs @@ -19,26 +19,18 @@ namespace Avalonia.Controls TextBox.WatermarkProperty.AddOwner(); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly StyledProperty MinimumPrefixLengthProperty = AvaloniaProperty.Register( nameof(MinimumPrefixLength), 1, validate: IsValidMinimumPrefixLength); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly StyledProperty MinimumPopulateDelayProperty = AvaloniaProperty.Register( nameof(MinimumPopulateDelay), @@ -46,13 +38,9 @@ namespace Avalonia.Controls validate: IsValidMinimumPopulateDelay); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly StyledProperty MaxDropDownHeightProperty = AvaloniaProperty.Register( nameof(MaxDropDownHeight), @@ -60,35 +48,23 @@ namespace Avalonia.Controls validate: IsValidMaxDropDownHeight); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly StyledProperty IsTextCompletionEnabledProperty = AvaloniaProperty.Register(nameof(IsTextCompletionEnabled)); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly StyledProperty ItemTemplateProperty = AvaloniaProperty.Register(nameof(ItemTemplate)); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty IsDropDownOpenProperty = AvaloniaProperty.RegisterDirect( nameof(IsDropDownOpen), @@ -96,13 +72,9 @@ namespace Avalonia.Controls (o, v) => o.IsDropDownOpen = v); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier the - /// - /// dependency property. + /// The identifier the property. public static readonly DirectProperty SelectedItemProperty = AvaloniaProperty.RegisterDirect( nameof(SelectedItem), @@ -112,13 +84,9 @@ namespace Avalonia.Controls enableDataValidation: true); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty TextProperty = TextBlock.TextProperty.AddOwnerWithDataValidation( o => o.Text, @@ -127,13 +95,9 @@ namespace Avalonia.Controls enableDataValidation: true); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty SearchTextProperty = AvaloniaProperty.RegisterDirect( nameof(SearchText), @@ -141,9 +105,7 @@ namespace Avalonia.Controls unsetValue: string.Empty); /// - /// Gets the identifier for the - /// - /// dependency property. + /// Gets the identifier for the property. /// public static readonly StyledProperty FilterModeProperty = AvaloniaProperty.Register( @@ -152,13 +114,9 @@ namespace Avalonia.Controls validate: IsValidFilterMode); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty?> ItemFilterProperty = AvaloniaProperty.RegisterDirect?>( nameof(ItemFilter), @@ -166,13 +124,9 @@ namespace Avalonia.Controls (o, v) => o.ItemFilter = v); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty?> TextFilterProperty = AvaloniaProperty.RegisterDirect?>( nameof(TextFilter), @@ -181,13 +135,9 @@ namespace Avalonia.Controls unsetValue: AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith)); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty?> ItemSelectorProperty = AvaloniaProperty.RegisterDirect?>( nameof(ItemSelector), @@ -195,13 +145,9 @@ namespace Avalonia.Controls (o, v) => o.ItemSelector = v); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty?> TextSelectorProperty = AvaloniaProperty.RegisterDirect?>( nameof(TextSelector), @@ -209,13 +155,9 @@ namespace Avalonia.Controls (o, v) => o.TextSelector = v); /// - /// Identifies the - /// - /// dependency property. + /// Identifies the property. /// - /// The identifier for the - /// - /// dependency property. + /// The identifier for the property. public static readonly DirectProperty ItemsProperty = AvaloniaProperty.RegisterDirect( nameof(Items), @@ -230,14 +172,11 @@ namespace Avalonia.Controls /// /// Gets or sets the minimum number of characters required to be entered - /// in the text box before the - /// displays - /// possible matches. - /// matches. + /// in the text box before the displays possible matches. /// /// /// The minimum number of characters to be entered in the text box - /// before the + /// before the /// displays possible matches. The default is 1. /// /// @@ -291,12 +230,12 @@ namespace Avalonia.Controls /// /// Gets or sets the minimum delay, after text is typed /// in the text box before the - /// control + /// control /// populates the list of possible matches in the drop-down. /// /// The minimum delay, after text is typed in /// the text box, but before the - /// populates + /// populates /// the list of possible matches in the drop-down. The default is 0. public TimeSpan MinimumPopulateDelay { @@ -306,10 +245,10 @@ namespace Avalonia.Controls /// /// Gets or sets the maximum height of the drop-down portion of the - /// control. + /// control. /// /// The maximum height of the drop-down portion of the - /// control. + /// control. /// The default is . /// The specified value is less than 0. public double MaxDropDownHeight @@ -335,7 +274,7 @@ namespace Avalonia.Controls /// /// Gets or sets the that /// is used to get the values for display in the text portion of - /// the + /// the /// control. /// /// The object used @@ -372,10 +311,10 @@ namespace Avalonia.Controls /// /// Gets or sets the text in the text box portion of the - /// control. + /// control. /// /// The text in the text box portion of the - /// control. + /// control. public string? Text { get => _text; @@ -384,12 +323,10 @@ namespace Avalonia.Controls /// /// Gets the text that is used to filter items in the - /// - /// item collection. + /// item collection. /// /// The text that is used to filter items in the - /// - /// item collection. + /// item collection. /// /// The SearchText value is typically the same as the /// Text property, but is set after the TextChanged event occurs @@ -414,17 +351,13 @@ namespace Avalonia.Controls /// /// Gets or sets how the text in the text box is used to filter items - /// specified by the - /// + /// specified by the /// property for display in the drop-down. /// - /// One of the - /// - /// values The default is - /// . - /// The specified value is - /// not a valid - /// . + /// One of the + /// values The default is . + /// The specified value is not a valid + /// . /// /// Use the FilterMode property to specify how possible matches are /// filtered. For example, possible matches can be filtered in a @@ -445,13 +378,11 @@ namespace Avalonia.Controls /// /// Gets or sets the custom method that uses user-entered text to filter - /// the items specified by the - /// + /// the items specified by the /// property for display in the drop-down. /// /// The custom method that uses the user-entered text to filter - /// the items specified by the - /// + /// the items specified by the /// property. The default is null. /// /// The filter mode is automatically set to Custom if you set the @@ -465,13 +396,11 @@ namespace Avalonia.Controls /// /// Gets or sets the custom method that uses the user-entered text to - /// filter items specified by the - /// + /// filter items specified by the /// property in a text-based way for display in the drop-down. /// /// The custom method that uses the user-entered text to filter - /// items specified by the - /// + /// items specified by the /// property in a text-based way for display in the drop-down. /// /// The search mode is automatically set to Custom if you set the @@ -485,13 +414,11 @@ namespace Avalonia.Controls /// /// Gets or sets the custom method that combines the user-entered - /// text and one of the items specified by the - /// . + /// text and one of the items specified by the . /// /// /// The custom method that combines the user-entered - /// text and one of the items specified by the - /// . + /// text and one of the items specified by the . /// public AutoCompleteSelector? ItemSelector { @@ -502,13 +429,11 @@ namespace Avalonia.Controls /// /// Gets or sets the custom method that combines the user-entered /// text and one of the items specified by the - /// - /// in a text-based way. + /// in a text-based way. /// /// /// The custom method that combines the user-entered - /// text and one of the items specified by the - /// + /// text and one of the items specified by the /// in a text-based way. /// public AutoCompleteSelector? TextSelector @@ -525,12 +450,10 @@ namespace Avalonia.Controls /// /// Gets or sets a collection that is used to generate the items for the - /// drop-down portion of the - /// control. + /// drop-down portion of the control. /// /// The collection that is used to generate the items of the - /// drop-down portion of the - /// control. + /// drop-down portion of the control. public IEnumerable? Items { get => _itemsEnumerable; From 44e416e2cd2d6a4c75ae6ac3b5b1da6edc330b01 Mon Sep 17 00:00:00 2001 From: robloo Date: Fri, 14 Oct 2022 21:19:28 -0400 Subject: [PATCH 7/8] AutoCompleteFilterMode comment fixes/improvements --- .../AutoCompleteBox/AutoCompleteFilterMode.cs | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs index 9aea49aef3..c17f5a19ab 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs @@ -3,13 +3,13 @@ // Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. +using System; + namespace Avalonia.Controls { /// - /// Specifies how text in the text box portion of the - /// control is used - /// to filter items specified by the - /// + /// Specifies how text in the text box portion of the + /// control is used to filter items specified by the /// property for display in the drop-down. /// public enum AutoCompleteFilterMode @@ -22,9 +22,9 @@ namespace Avalonia.Controls /// /// Specifies a culture-sensitive, case-insensitive filter where the /// returned items start with the specified text. The filter uses the - /// + /// /// method, specifying - /// as + /// as /// the string comparison criteria. /// StartsWith = 1, @@ -32,9 +32,9 @@ namespace Avalonia.Controls /// /// Specifies a culture-sensitive, case-sensitive filter where the /// returned items start with the specified text. The filter uses the - /// + /// /// method, specifying - /// as the string + /// as the string /// comparison criteria. /// StartsWithCaseSensitive = 2, @@ -42,9 +42,9 @@ namespace Avalonia.Controls /// /// Specifies an ordinal, case-insensitive filter where the returned /// items start with the specified text. The filter uses the - /// + /// /// method, specifying - /// as the + /// as the /// string comparison criteria. /// StartsWithOrdinal = 3, @@ -52,8 +52,8 @@ namespace Avalonia.Controls /// /// Specifies an ordinal, case-sensitive filter where the returned items /// start with the specified text. The filter uses the - /// - /// method, specifying as + /// + /// method, specifying as /// the string comparison criteria. /// StartsWithOrdinalCaseSensitive = 4, @@ -85,9 +85,9 @@ namespace Avalonia.Controls /// /// Specifies a culture-sensitive, case-insensitive filter where the /// returned items equal the specified text. The filter uses the - /// + /// /// method, specifying - /// as + /// as /// the search comparison criteria. /// Equals = 9, @@ -95,9 +95,9 @@ namespace Avalonia.Controls /// /// Specifies a culture-sensitive, case-sensitive filter where the /// returned items equal the specified text. The filter uses the - /// + /// /// method, specifying - /// as the string + /// as the string /// comparison criteria. /// EqualsCaseSensitive = 10, @@ -105,9 +105,9 @@ namespace Avalonia.Controls /// /// Specifies an ordinal, case-insensitive filter where the returned /// items equal the specified text. The filter uses the - /// + /// /// method, specifying - /// as the + /// as the /// string comparison criteria. /// EqualsOrdinal = 11, @@ -115,17 +115,15 @@ namespace Avalonia.Controls /// /// Specifies an ordinal, case-sensitive filter where the returned items /// equal the specified text. The filter uses the - /// - /// method, specifying as + /// + /// method, specifying as /// the string comparison criteria. /// EqualsOrdinalCaseSensitive = 12, /// /// Specifies that a custom filter is used. This mode is used when the - /// - /// or - /// + /// or /// properties are set. /// Custom = 13, From 555091aedcacd484326a67883a4429814bbde348 Mon Sep 17 00:00:00 2001 From: Herman Kirshin Date: Sat, 15 Oct 2022 21:48:15 +0300 Subject: [PATCH 8/8] Fixed double value validation in RangeBase --- src/Avalonia.Controls/Primitives/RangeBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/RangeBase.cs b/src/Avalonia.Controls/Primitives/RangeBase.cs index acb8e0f006..38d848d69b 100644 --- a/src/Avalonia.Controls/Primitives/RangeBase.cs +++ b/src/Avalonia.Controls/Primitives/RangeBase.cs @@ -175,7 +175,7 @@ namespace Avalonia.Controls.Primitives /// The value. private static bool ValidateDouble(double value) { - return !double.IsInfinity(value) || !double.IsNaN(value); + return !double.IsInfinity(value) && !double.IsNaN(value); } ///