From 2b2eb8261a7b7a1a59140f51339c918de059b58d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 28 Mar 2023 22:04:27 +0200 Subject: [PATCH] DataGrid.Items -> ItemsSource. --- .../ControlCatalog/Pages/DataGridPage.xaml | 2 +- .../ControlCatalog/Pages/DataGridPage.xaml.cs | 4 +-- src/Avalonia.Controls.DataGrid/DataGrid.cs | 27 ++++++++----------- .../DataGridBoundColumn.cs | 2 +- .../DataGridDataConnection.cs | 4 +-- .../DataGridTemplateColumn.cs | 4 +-- .../Diagnostics/Views/ControlDetailsView.xaml | 2 +- tests/Avalonia.LeakTests/ControlTests.cs | 2 +- 8 files changed, 21 insertions(+), 26 deletions(-) diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml b/samples/ControlCatalog/Pages/DataGridPage.xaml index c39e9f0a81..fb097da71b 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml @@ -94,7 +94,7 @@ + ItemsSource="{Binding DataGrid3Source}"> diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs index b0c3e3a553..617b0db5ed 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs @@ -36,7 +36,7 @@ namespace ControlCatalog.Pages collectionView1.SortDescriptions.Add(dataGridSortDescription); } }; - dg1.Items = collectionView1; + dg1.ItemsSource = collectionView1; var dg2 = this.Get("dataGridGrouping"); dg2.IsReadOnly = true; @@ -44,7 +44,7 @@ namespace ControlCatalog.Pages var collectionView2 = new DataGridCollectionView(Countries.All); collectionView2.GroupDescriptions.Add(new DataGridPathGroupDescription("Region")); - dg2.Items = collectionView2; + dg2.ItemsSource = collectionView2; var dg3 = this.Get("dataGridEdit"); dg3.IsReadOnly = false; diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index 944e7b737a..802f4c6e13 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -152,8 +152,6 @@ namespace Avalonia.Controls private double _verticalOffset; private byte _verticalScrollChangesIgnored; - private IEnumerable _items; - public event EventHandler HorizontalScroll; public event EventHandler VerticalScroll; @@ -652,21 +650,18 @@ namespace Avalonia.Controls } /// - /// Identifies the ItemsSource dependency property. + /// Identifies the ItemsSource property. /// - public static readonly DirectProperty ItemsProperty = - AvaloniaProperty.RegisterDirect( - nameof(Items), - o => o.Items, - (o, v) => o.Items = v); + public static readonly StyledProperty ItemsSourceProperty = + AvaloniaProperty.Register(nameof(ItemsSource)); /// /// Gets or sets a collection that is used to generate the content of the control. /// - public IEnumerable Items + public IEnumerable ItemsSource { - get { return _items; } - set { SetAndRaise(ItemsProperty, ref _items, value); } + get => GetValue(ItemsSourceProperty); + set => SetValue(ItemsSourceProperty, value); } public static readonly StyledProperty AreRowDetailsFrozenProperty = @@ -713,7 +708,7 @@ namespace Avalonia.Controls HorizontalScrollBarVisibilityProperty, VerticalScrollBarVisibilityProperty); - ItemsProperty.Changed.AddClassHandler((x, e) => x.OnItemsPropertyChanged(e)); + ItemsSourceProperty.Changed.AddClassHandler((x, e) => x.OnItemsSourcePropertyChanged(e)); CanUserResizeColumnsProperty.Changed.AddClassHandler((x, e) => x.OnCanUserResizeColumnsChanged(e)); ColumnWidthProperty.Changed.AddClassHandler((x, e) => x.OnColumnWidthChanged(e)); FrozenColumnCountProperty.Changed.AddClassHandler((x, e) => x.OnFrozenColumnCountChanged(e)); @@ -816,10 +811,10 @@ namespace Avalonia.Controls } /// - /// ItemsProperty property changed handler. + /// ItemsSourceProperty property changed handler. /// /// The event arguments. - private void OnItemsPropertyChanged(AvaloniaPropertyChangedEventArgs e) + private void OnItemsSourcePropertyChanged(AvaloniaPropertyChangedEventArgs e) { if (!_areHandlersSuspended) { @@ -830,7 +825,7 @@ namespace Avalonia.Controls if (LoadingOrUnloadingRow) { - SetValueNoCallback(ItemsProperty, oldValue); + SetValueNoCallback(ItemsSourceProperty, oldValue); throw DataGridError.DataGrid.CannotChangeItemsWhenLoadingRows(); } @@ -1855,7 +1850,7 @@ namespace Avalonia.Controls { get { - if (CurrentSlot == -1 || Items == null || RowGroupHeadersTable.Contains(CurrentSlot)) + if (CurrentSlot == -1 || ItemsSource == null || RowGroupHeadersTable.Contains(CurrentSlot)) { return null; } diff --git a/src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs index 110590fef2..61a1eb2bf0 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs @@ -25,7 +25,7 @@ namespace Avalonia.Controls /// //TODO Binding [AssignBinding] - [InheritDataTypeFromItems(nameof(DataGrid.Items), AncestorType = typeof(DataGrid))] + [InheritDataTypeFromItems(nameof(DataGrid.ItemsSource), AncestorType = typeof(DataGrid))] public virtual IBinding Binding { get diff --git a/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs b/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs index ae52e5f970..ee9cc04420 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs @@ -122,9 +122,9 @@ namespace Avalonia.Controls // We need to use the raw ItemsSource as opposed to DataSource because DataSource // may be the ItemsSource wrapped in a collection view, in which case we wouldn't // be able to take T to be the type if we're given IEnumerable - if (_dataType == null && _owner.Items != null) + if (_dataType == null && _owner.ItemsSource != null) { - _dataType = _owner.Items.GetItemType(); + _dataType = _owner.ItemsSource.GetItemType(); } return _dataType; } diff --git a/src/Avalonia.Controls.DataGrid/DataGridTemplateColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridTemplateColumn.cs index 00318e2dd8..0bfb4b6913 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridTemplateColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridTemplateColumn.cs @@ -24,7 +24,7 @@ namespace Avalonia.Controls (o, v) => o.CellTemplate = v); [Content] - [InheritDataTypeFromItems(nameof(DataGrid.Items), AncestorType = typeof(DataGrid))] + [InheritDataTypeFromItems(nameof(DataGrid.ItemsSource), AncestorType = typeof(DataGrid))] public IDataTemplate CellTemplate { get { return _cellTemplate; } @@ -51,7 +51,7 @@ namespace Avalonia.Controls /// /// If this property is the column is read-only. /// - [InheritDataTypeFromItems(nameof(DataGrid.Items), AncestorType = typeof(DataGrid))] + [InheritDataTypeFromItems(nameof(DataGrid.ItemsSource), AncestorType = typeof(DataGrid))] public IDataTemplate CellEditingTemplate { get => _cellEditingCellTemplate; diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml index c2e63da31c..63b002d110 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml @@ -51,7 +51,7 @@