Browse Source

AutoCompleteBox.Items -> ItemsSource.

pull/10831/head
Steven Kirk 4 years ago
parent
commit
027bd2313a
  1. 4
      samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs
  2. 4
      samples/ControlCatalog/Pages/DialogsPage.xaml
  3. 36
      src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs
  4. 26
      src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
  5. 2
      src/Avalonia.Controls/Utils/ISelectionAdapter.cs
  6. 2
      src/Avalonia.Controls/Utils/SelectingItemsControlSelectionAdapter.cs
  7. 10
      tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs

4
samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs

@ -114,7 +114,7 @@ namespace ControlCatalog.Pages
foreach (AutoCompleteBox box in GetAllAutoCompleteBox().Where(x => x.Name != "CustomAutocompleteBox")) foreach (AutoCompleteBox box in GetAllAutoCompleteBox().Where(x => x.Name != "CustomAutocompleteBox"))
{ {
box.Items = States; box.ItemsSource = States;
} }
var converter = new FuncMultiValueConverter<string, string>(parts => var converter = new FuncMultiValueConverter<string, string>(parts =>
@ -132,7 +132,7 @@ namespace ControlCatalog.Pages
asyncBox.AsyncPopulator = PopulateAsync; asyncBox.AsyncPopulator = PopulateAsync;
var customAutocompleteBox = this.Get<AutoCompleteBox>("CustomAutocompleteBox"); var customAutocompleteBox = this.Get<AutoCompleteBox>("CustomAutocompleteBox");
customAutocompleteBox.Items = Sentences.SelectMany(x => x); customAutocompleteBox.ItemsSource = Sentences.SelectMany(x => x);
customAutocompleteBox.TextFilter = LastWordContains; customAutocompleteBox.TextFilter = LastWordContains;
customAutocompleteBox.TextSelector = AppendWord; customAutocompleteBox.TextSelector = AppendWord;
} }

4
samples/ControlCatalog/Pages/DialogsPage.xaml

@ -45,7 +45,7 @@
</Expander> </Expander>
<AutoCompleteBox x:Name="CurrentFolderBox" Watermark="Write full path/uri or well known folder name"> <AutoCompleteBox x:Name="CurrentFolderBox" Watermark="Write full path/uri or well known folder name">
<AutoCompleteBox.Items> <AutoCompleteBox.ItemsSource>
<generic:List x:TypeArguments="storage:WellKnownFolder"> <generic:List x:TypeArguments="storage:WellKnownFolder">
<storage:WellKnownFolder>Desktop</storage:WellKnownFolder> <storage:WellKnownFolder>Desktop</storage:WellKnownFolder>
<storage:WellKnownFolder>Documents</storage:WellKnownFolder> <storage:WellKnownFolder>Documents</storage:WellKnownFolder>
@ -54,7 +54,7 @@
<storage:WellKnownFolder>Videos</storage:WellKnownFolder> <storage:WellKnownFolder>Videos</storage:WellKnownFolder>
<storage:WellKnownFolder>Music</storage:WellKnownFolder> <storage:WellKnownFolder>Music</storage:WellKnownFolder>
</generic:List> </generic:List>
</AutoCompleteBox.Items> </AutoCompleteBox.ItemsSource>
</AutoCompleteBox> </AutoCompleteBox>
<TextBlock x:Name="PickerLastResultsVisible" <TextBlock x:Name="PickerLastResultsVisible"

36
src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs

@ -143,12 +143,12 @@ namespace Avalonia.Controls
nameof(TextSelector)); nameof(TextSelector));
/// <summary> /// <summary>
/// Identifies the <see cref="Items" /> property. /// Identifies the <see cref="ItemsSource" /> property.
/// </summary> /// </summary>
/// <value>The identifier for the <see cref="Items" /> property.</value> /// <value>The identifier for the <see cref="ItemsSource" /> property.</value>
public static readonly StyledProperty<IEnumerable?> ItemsProperty = public static readonly StyledProperty<IEnumerable?> ItemsSourceProperty =
AvaloniaProperty.Register<AutoCompleteBox, IEnumerable?>( AvaloniaProperty.Register<AutoCompleteBox, IEnumerable?>(
nameof(Items)); nameof(ItemsSource));
/// <summary> /// <summary>
/// Identifies the <see cref="AsyncPopulator" /> property. /// Identifies the <see cref="AsyncPopulator" /> property.
@ -311,10 +311,10 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets the text that is used to filter items in the /// Gets the text that is used to filter items in the
/// <see cref="Items" /> item collection. /// <see cref="ItemsSource" /> item collection.
/// </summary> /// </summary>
/// <value>The text that is used to filter items in the /// <value>The text that is used to filter items in the
/// <see cref="Items" /> item collection.</value> /// <see cref="ItemsSource" /> item collection.</value>
/// <remarks> /// <remarks>
/// The SearchText value is typically the same as the /// The SearchText value is typically the same as the
/// Text property, but is set after the TextChanged event occurs /// Text property, but is set after the TextChanged event occurs
@ -339,7 +339,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets how the text in the text box is used to filter items /// Gets or sets how the text in the text box is used to filter items
/// specified by the <see cref="Items" /> /// specified by the <see cref="ItemsSource" />
/// property for display in the drop-down. /// property for display in the drop-down.
/// </summary> /// </summary>
/// <value>One of the <see cref="AutoCompleteFilterMode" /> /// <value>One of the <see cref="AutoCompleteFilterMode" />
@ -366,11 +366,11 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets the custom method that uses user-entered text to filter /// Gets or sets the custom method that uses user-entered text to filter
/// the items specified by the <see cref="Items" /> /// the items specified by the <see cref="ItemsSource" />
/// property for display in the drop-down. /// property for display in the drop-down.
/// </summary> /// </summary>
/// <value>The custom method that uses the user-entered text to filter /// <value>The custom method that uses the user-entered text to filter
/// the items specified by the <see cref="Items" /> /// the items specified by the <see cref="ItemsSource" />
/// property. The default is null.</value> /// property. The default is null.</value>
/// <remarks> /// <remarks>
/// The filter mode is automatically set to Custom if you set the /// The filter mode is automatically set to Custom if you set the
@ -384,11 +384,11 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets the custom method that uses the user-entered text to /// Gets or sets the custom method that uses the user-entered text to
/// filter items specified by the <see cref="Items" /> /// filter items specified by the <see cref="ItemsSource" />
/// property in a text-based way for display in the drop-down. /// property in a text-based way for display in the drop-down.
/// </summary> /// </summary>
/// <value>The custom method that uses the user-entered text to filter /// <value>The custom method that uses the user-entered text to filter
/// items specified by the <see cref="Items" /> /// items specified by the <see cref="ItemsSource" />
/// property in a text-based way for display in the drop-down.</value> /// property in a text-based way for display in the drop-down.</value>
/// <remarks> /// <remarks>
/// The search mode is automatically set to Custom if you set the /// The search mode is automatically set to Custom if you set the
@ -402,11 +402,11 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets the custom method that combines the user-entered /// Gets or sets the custom method that combines the user-entered
/// text and one of the items specified by the <see cref="Items" />. /// text and one of the items specified by the <see cref="ItemsSource" />.
/// </summary> /// </summary>
/// <value> /// <value>
/// The custom method that combines the user-entered /// The custom method that combines the user-entered
/// text and one of the items specified by the <see cref="Items" />. /// text and one of the items specified by the <see cref="ItemsSource" />.
/// </value> /// </value>
public AutoCompleteSelector<object>? ItemSelector public AutoCompleteSelector<object>? ItemSelector
{ {
@ -417,11 +417,11 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets the custom method that combines the user-entered /// 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
/// <see cref="Items" /> in a text-based way. /// <see cref="ItemsSource" /> in a text-based way.
/// </summary> /// </summary>
/// <value> /// <value>
/// The custom method that combines the user-entered /// The custom method that combines the user-entered
/// text and one of the items specified by the <see cref="Items" /> /// text and one of the items specified by the <see cref="ItemsSource" />
/// in a text-based way. /// in a text-based way.
/// </value> /// </value>
public AutoCompleteSelector<string?>? TextSelector public AutoCompleteSelector<string?>? TextSelector
@ -442,10 +442,10 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
/// <value>The collection that is used to generate the items of the /// <value>The collection that is used to generate the items of the
/// drop-down portion of the <see cref="AutoCompleteBox" /> control.</value> /// drop-down portion of the <see cref="AutoCompleteBox" /> control.</value>
public IEnumerable? Items public IEnumerable? ItemsSource
{ {
get => GetValue(ItemsProperty); get => GetValue(ItemsSourceProperty);
set => SetValue(ItemsProperty, value); set => SetValue(ItemsSourceProperty, value);
} }
} }
} }

26
src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs

@ -419,9 +419,9 @@ namespace Avalonia.Controls
/// ItemsSourceProperty property changed handler. /// ItemsSourceProperty property changed handler.
/// </summary> /// </summary>
/// <param name="e">Event arguments.</param> /// <param name="e">Event arguments.</param>
private void OnItemsPropertyChanged(AvaloniaPropertyChangedEventArgs e) private void OnItemsSourcePropertyChanged(AvaloniaPropertyChangedEventArgs e)
{ {
OnItemsChanged((IEnumerable?)e.NewValue); OnItemsSourceChanged((IEnumerable?)e.NewValue);
} }
private void OnItemTemplatePropertyChanged(AvaloniaPropertyChangedEventArgs e) private void OnItemTemplatePropertyChanged(AvaloniaPropertyChangedEventArgs e)
@ -461,7 +461,7 @@ namespace Avalonia.Controls
SearchTextProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnSearchTextPropertyChanged(e)); SearchTextProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnSearchTextPropertyChanged(e));
FilterModeProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnFilterModePropertyChanged(e)); FilterModeProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnFilterModePropertyChanged(e));
ItemFilterProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemFilterPropertyChanged(e)); ItemFilterProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemFilterPropertyChanged(e));
ItemsProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemsPropertyChanged(e)); ItemsSourceProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemsSourcePropertyChanged(e));
ItemTemplateProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemTemplatePropertyChanged(e)); ItemTemplateProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemTemplatePropertyChanged(e));
IsEnabledProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnControlIsEnabledChanged(e)); IsEnabledProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnControlIsEnabledChanged(e));
} }
@ -559,7 +559,7 @@ namespace Avalonia.Controls
_adapter.Commit -= OnAdapterSelectionComplete; _adapter.Commit -= OnAdapterSelectionComplete;
_adapter.Cancel -= OnAdapterSelectionCanceled; _adapter.Cancel -= OnAdapterSelectionCanceled;
_adapter.Cancel -= OnAdapterSelectionComplete; _adapter.Cancel -= OnAdapterSelectionComplete;
_adapter.Items = null; _adapter.ItemsSource = null;
} }
_adapter = value; _adapter = value;
@ -570,7 +570,7 @@ namespace Avalonia.Controls
_adapter.Commit += OnAdapterSelectionComplete; _adapter.Commit += OnAdapterSelectionComplete;
_adapter.Cancel += OnAdapterSelectionCanceled; _adapter.Cancel += OnAdapterSelectionCanceled;
_adapter.Cancel += OnAdapterSelectionComplete; _adapter.Cancel += OnAdapterSelectionComplete;
_adapter.Items = _view; _adapter.ItemsSource = _view;
} }
} }
} }
@ -1128,7 +1128,7 @@ namespace Avalonia.Controls
{ {
if (!cancellationToken.IsCancellationRequested) if (!cancellationToken.IsCancellationRequested)
{ {
SetCurrentValue(ItemsProperty, resultList); SetCurrentValue(ItemsSourceProperty, resultList);
PopulateComplete(); PopulateComplete();
} }
}); });
@ -1475,7 +1475,7 @@ namespace Avalonia.Controls
/// adapter's ItemsSource to the view if appropriate. /// adapter's ItemsSource to the view if appropriate.
/// </summary> /// </summary>
/// <param name="newValue">The new enumerable reference.</param> /// <param name="newValue">The new enumerable reference.</param>
private void OnItemsChanged(IEnumerable? newValue) private void OnItemsSourceChanged(IEnumerable? newValue)
{ {
// Remove handler for oldValue.CollectionChanged (if present) // Remove handler for oldValue.CollectionChanged (if present)
_collectionChangeSubscription?.Dispose(); _collectionChangeSubscription?.Dispose();
@ -1492,9 +1492,9 @@ namespace Avalonia.Controls
// Clear and set the view on the selection adapter // Clear and set the view on the selection adapter
ClearView(); ClearView();
if (SelectionAdapter != null && SelectionAdapter.Items != _view) if (SelectionAdapter != null && SelectionAdapter.ItemsSource != _view)
{ {
SelectionAdapter.Items = _view; SelectionAdapter.ItemsSource = _view;
} }
if (IsDropDownOpen) if (IsDropDownOpen)
{ {
@ -1545,9 +1545,9 @@ namespace Avalonia.Controls
{ {
// Significant changes to the underlying data. // Significant changes to the underlying data.
ClearView(); ClearView();
if (Items != null) if (ItemsSource != null)
{ {
_items = new List<object>(Items.Cast<object>()); _items = new List<object>(ItemsSource.Cast<object>());
} }
} }
@ -1582,9 +1582,9 @@ namespace Avalonia.Controls
PopulatedEventArgs populated = new PopulatedEventArgs(new ReadOnlyCollection<object>(_view!)); PopulatedEventArgs populated = new PopulatedEventArgs(new ReadOnlyCollection<object>(_view!));
OnPopulated(populated); OnPopulated(populated);
if (SelectionAdapter != null && SelectionAdapter.Items != _view) if (SelectionAdapter != null && SelectionAdapter.ItemsSource != _view)
{ {
SelectionAdapter.Items = _view; SelectionAdapter.ItemsSource = _view;
} }
bool isDropDownOpen = _userCalledPopulate && (_view!.Count > 0); bool isDropDownOpen = _userCalledPopulate && (_view!.Count > 0);

2
src/Avalonia.Controls/Utils/ISelectionAdapter.cs

@ -36,7 +36,7 @@ namespace Avalonia.Controls.Utils
/// </summary> /// </summary>
/// <value>The collection that is used to generate content for the /// <value>The collection that is used to generate content for the
/// selection adapter.</value> /// selection adapter.</value>
IEnumerable? Items { get; set; } IEnumerable? ItemsSource { get; set; }
/// <summary> /// <summary>
/// Occurs when a selected item is not cancelled and is committed as the /// Occurs when a selected item is not cancelled and is committed as the

2
src/Avalonia.Controls/Utils/SelectingItemsControlSelectionAdapter.cs

@ -140,7 +140,7 @@ namespace Avalonia.Controls.Utils
/// </summary> /// </summary>
/// <value>The collection used to generate content for the selection /// <value>The collection used to generate content for the selection
/// adapter.</value> /// adapter.</value>
public IEnumerable? Items public IEnumerable? ItemsSource
{ {
get get
{ {

10
tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs

@ -89,7 +89,7 @@ namespace Avalonia.Controls.UnitTests
bool closeEvent = false; bool closeEvent = false;
control.DropDownOpened += (s, e) => openEvent = true; control.DropDownOpened += (s, e) => openEvent = true;
control.DropDownClosed += (s, e) => closeEvent = true; control.DropDownClosed += (s, e) => closeEvent = true;
control.Items = CreateSimpleStringArray(); control.ItemsSource = CreateSimpleStringArray();
textbox.Text = "a"; textbox.Text = "a";
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
@ -258,7 +258,7 @@ namespace Avalonia.Controls.UnitTests
control.FilterMode = AutoCompleteFilterMode.None; control.FilterMode = AutoCompleteFilterMode.None;
control.Populating += (s, e) => control.Populating += (s, e) =>
{ {
control.Items = new string[] { custom }; control.ItemsSource = new string[] { custom };
Assert.Equal(search, e.Parameter); Assert.Equal(search, e.Parameter);
}; };
control.Populated += (s, e) => control.Populated += (s, e) =>
@ -380,7 +380,7 @@ namespace Avalonia.Controls.UnitTests
{ {
RunTest((control, textbox) => RunTest((control, textbox) =>
{ {
object selectedItem = control.Items.Cast<object>().First(); object selectedItem = control.ItemsSource.Cast<object>().First();
string input = "42"; string input = "42";
control.TextSelector = (text, item) => text + item; control.TextSelector = (text, item) => text + item;
@ -397,7 +397,7 @@ namespace Avalonia.Controls.UnitTests
{ {
RunTest((control, textbox) => RunTest((control, textbox) =>
{ {
object selectedItem = control.Items.Cast<object>().First(); object selectedItem = control.ItemsSource.Cast<object>().First();
string input = "42"; string input = "42";
control.ItemSelector = (text, item) => text + item; control.ItemSelector = (text, item) => text + item;
@ -1053,7 +1053,7 @@ namespace Avalonia.Controls.UnitTests
using (UnitTestApplication.Start(Services)) using (UnitTestApplication.Start(Services))
{ {
AutoCompleteBox control = CreateControl(); AutoCompleteBox control = CreateControl();
control.Items = CreateSimpleStringArray(); control.ItemsSource = CreateSimpleStringArray();
TextBox textBox = GetTextBox(control); TextBox textBox = GetTextBox(control);
var window = new Window {Content = control}; var window = new Window {Content = control};
window.ApplyStyling(); window.ApplyStyling();

Loading…
Cancel
Save