Browse Source

AutoCompleteBox.Items -> ItemsSource.

pull/10831/head
Steven Kirk 3 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"))
{
box.Items = States;
box.ItemsSource = States;
}
var converter = new FuncMultiValueConverter<string, string>(parts =>
@ -132,7 +132,7 @@ namespace ControlCatalog.Pages
asyncBox.AsyncPopulator = PopulateAsync;
var customAutocompleteBox = this.Get<AutoCompleteBox>("CustomAutocompleteBox");
customAutocompleteBox.Items = Sentences.SelectMany(x => x);
customAutocompleteBox.ItemsSource = Sentences.SelectMany(x => x);
customAutocompleteBox.TextFilter = LastWordContains;
customAutocompleteBox.TextSelector = AppendWord;
}

4
samples/ControlCatalog/Pages/DialogsPage.xaml

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

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

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

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

@ -419,9 +419,9 @@ namespace Avalonia.Controls
/// ItemsSourceProperty property changed handler.
/// </summary>
/// <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)
@ -461,7 +461,7 @@ namespace Avalonia.Controls
SearchTextProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnSearchTextPropertyChanged(e));
FilterModeProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnFilterModePropertyChanged(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));
IsEnabledProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnControlIsEnabledChanged(e));
}
@ -559,7 +559,7 @@ namespace Avalonia.Controls
_adapter.Commit -= OnAdapterSelectionComplete;
_adapter.Cancel -= OnAdapterSelectionCanceled;
_adapter.Cancel -= OnAdapterSelectionComplete;
_adapter.Items = null;
_adapter.ItemsSource = null;
}
_adapter = value;
@ -570,7 +570,7 @@ namespace Avalonia.Controls
_adapter.Commit += OnAdapterSelectionComplete;
_adapter.Cancel += OnAdapterSelectionCanceled;
_adapter.Cancel += OnAdapterSelectionComplete;
_adapter.Items = _view;
_adapter.ItemsSource = _view;
}
}
}
@ -1128,7 +1128,7 @@ namespace Avalonia.Controls
{
if (!cancellationToken.IsCancellationRequested)
{
SetCurrentValue(ItemsProperty, resultList);
SetCurrentValue(ItemsSourceProperty, resultList);
PopulateComplete();
}
});
@ -1475,7 +1475,7 @@ namespace Avalonia.Controls
/// adapter's ItemsSource to the view if appropriate.
/// </summary>
/// <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)
_collectionChangeSubscription?.Dispose();
@ -1492,9 +1492,9 @@ namespace Avalonia.Controls
// Clear and set the view on the selection adapter
ClearView();
if (SelectionAdapter != null && SelectionAdapter.Items != _view)
if (SelectionAdapter != null && SelectionAdapter.ItemsSource != _view)
{
SelectionAdapter.Items = _view;
SelectionAdapter.ItemsSource = _view;
}
if (IsDropDownOpen)
{
@ -1545,9 +1545,9 @@ namespace Avalonia.Controls
{
// Significant changes to the underlying data.
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!));
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);

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

@ -36,7 +36,7 @@ namespace Avalonia.Controls.Utils
/// </summary>
/// <value>The collection that is used to generate content for the
/// selection adapter.</value>
IEnumerable? Items { get; set; }
IEnumerable? ItemsSource { get; set; }
/// <summary>
/// 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>
/// <value>The collection used to generate content for the selection
/// adapter.</value>
public IEnumerable? Items
public IEnumerable? ItemsSource
{
get
{

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

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

Loading…
Cancel
Save