diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs new file mode 100644 index 0000000000..ecbe01d8b7 --- /dev/null +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs @@ -0,0 +1,463 @@ +// (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 property. + /// + /// The identifier for the property. + public static readonly StyledProperty MinimumPrefixLengthProperty = + AvaloniaProperty.Register( + nameof(MinimumPrefixLength), 1, + validate: IsValidMinimumPrefixLength); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly StyledProperty MinimumPopulateDelayProperty = + AvaloniaProperty.Register( + nameof(MinimumPopulateDelay), + TimeSpan.Zero, + validate: IsValidMinimumPopulateDelay); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly StyledProperty MaxDropDownHeightProperty = + AvaloniaProperty.Register( + nameof(MaxDropDownHeight), + double.PositiveInfinity, + validate: IsValidMaxDropDownHeight); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly StyledProperty IsTextCompletionEnabledProperty = + AvaloniaProperty.Register(nameof(IsTextCompletionEnabled)); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly StyledProperty ItemTemplateProperty = + AvaloniaProperty.Register(nameof(ItemTemplate)); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly DirectProperty IsDropDownOpenProperty = + AvaloniaProperty.RegisterDirect( + nameof(IsDropDownOpen), + o => o.IsDropDownOpen, + (o, v) => o.IsDropDownOpen = v); + + /// + /// Identifies the property. + /// + /// The identifier the 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 property. + /// + /// The identifier for the property. + public static readonly DirectProperty TextProperty = + TextBlock.TextProperty.AddOwnerWithDataValidation( + o => o.Text, + (o, v) => o.Text = v, + defaultBindingMode: BindingMode.TwoWay, + enableDataValidation: true); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly DirectProperty SearchTextProperty = + AvaloniaProperty.RegisterDirect( + nameof(SearchText), + o => o.SearchText, + unsetValue: string.Empty); + + /// + /// Gets the identifier for the property. + /// + public static readonly StyledProperty FilterModeProperty = + AvaloniaProperty.Register( + nameof(FilterMode), + defaultValue: AutoCompleteFilterMode.StartsWith, + validate: IsValidFilterMode); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly DirectProperty?> ItemFilterProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(ItemFilter), + o => o.ItemFilter, + (o, v) => o.ItemFilter = v); + + /// + /// Identifies the property. + /// + /// The identifier for the 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 property. + /// + /// The identifier for the property. + public static readonly DirectProperty?> ItemSelectorProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(ItemSelector), + o => o.ItemSelector, + (o, v) => o.ItemSelector = v); + + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly DirectProperty?> TextSelectorProperty = + AvaloniaProperty.RegisterDirect?>( + nameof(TextSelector), + o => o.TextSelector, + (o, v) => o.TextSelector = v); + + /// + /// Identifies the property. + /// + /// The identifier for the 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. + /// + /// + /// 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.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs similarity index 71% rename from src/Avalonia.Controls/AutoCompleteBox.cs rename to src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs index 8a8c4ead86..a027b8b650 100644 --- a/src/Avalonia.Controls/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 @@ -257,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. @@ -394,221 +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)); + public static readonly RoutedEvent SelectionChangedEvent = + RoutedEvent.Register( + nameof(SelectionChanged), + RoutingStrategies.Bubble, + typeof(AutoCompleteBox)); /// - /// Identifies the - /// - /// dependency property. + /// Defines the event. /// - /// 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 TextChangedEvent = + RoutedEvent.Register( + nameof(TextChanged), + RoutingStrategies.Bubble); private static bool IsValidMinimumPrefixLength(int value) => value >= -1; @@ -871,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 { return 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 { return 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 { return 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 { return 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 { return 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 { return _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 { return _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 { return _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 { return _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 { return _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 { return GetValue(FilterModeProperty); } - set { SetValue(FilterModeProperty, value); } - } - - public string? Watermark - { - get { return 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 { return _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 { return _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 { return _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 { return _textSelector; } - set { SetAndRaise(TextSelectorProperty, ref _textSelector, value); } - } - - public Func>>? AsyncPopulator - { - get { return _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 { return _itemsEnumerable; } - set { SetAndRaise(ItemsProperty, ref _itemsEnumerable, value); } - } - /// /// Gets or sets the drop down popup control. /// @@ -1190,7 +497,7 @@ namespace Avalonia.Controls /// private TextBox? TextBox { - get { return _textBox; } + get => _textBox; set { _textBoxSubscriptions?.Dispose(); @@ -1254,7 +561,7 @@ namespace Avalonia.Controls /// protected ISelectionAdapter? SelectionAdapter { - get { return _adapter; } + get => _adapter; set { if (_adapter != null) @@ -1529,10 +836,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 +1001,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 +1293,7 @@ namespace Avalonia.Controls if (callTextChanged) { - OnTextChanged(new RoutedEventArgs()); + OnTextChanged(new TextChangedEventArgs(TextChangedEvent)); } } @@ -2740,8 +2048,6 @@ namespace Avalonia.Controls /// private IBinding? _binding; - #region public T Value - /// /// Identifies the Value dependency property. /// @@ -2753,18 +2059,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; diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs new file mode 100644 index 0000000000..c17f5a19ab --- /dev/null +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs @@ -0,0 +1,131 @@ +// (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; + +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; + } + } +} 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); } ///