Browse Source

DataGrid.Items -> ItemsSource.

pull/10831/head
Steven Kirk 3 years ago
parent
commit
2b2eb8261a
  1. 2
      samples/ControlCatalog/Pages/DataGridPage.xaml
  2. 4
      samples/ControlCatalog/Pages/DataGridPage.xaml.cs
  3. 27
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  4. 2
      src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs
  5. 4
      src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs
  6. 4
      src/Avalonia.Controls.DataGrid/DataGridTemplateColumn.cs
  7. 2
      src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml
  8. 2
      tests/Avalonia.LeakTests/ControlTests.cs

2
samples/ControlCatalog/Pages/DataGridPage.xaml

@ -94,7 +94,7 @@
<Grid RowDefinitions="*,Auto">
<!-- Example of columns inheriting the data type from the Items source -->
<DataGrid Name="dataGridEdit" Margin="12" Grid.Row="0"
Items="{Binding DataGrid3Source}">
ItemsSource="{Binding DataGrid3Source}">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" Width="2*" FontSize="{Binding #FontSizeSlider.Value, Mode=OneWay}" />
<DataGridTextColumn Header="Last" Binding="{Binding LastName}" Width="2*" FontSize="{Binding #FontSizeSlider.Value, Mode=OneWay}" />

4
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<DataGrid>("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<DataGrid>("dataGridEdit");
dg3.IsReadOnly = false;

27
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<ScrollEventArgs> HorizontalScroll;
public event EventHandler<ScrollEventArgs> VerticalScroll;
@ -652,21 +650,18 @@ namespace Avalonia.Controls
}
/// <summary>
/// Identifies the ItemsSource dependency property.
/// Identifies the ItemsSource property.
/// </summary>
public static readonly DirectProperty<DataGrid, IEnumerable> ItemsProperty =
AvaloniaProperty.RegisterDirect<DataGrid, IEnumerable>(
nameof(Items),
o => o.Items,
(o, v) => o.Items = v);
public static readonly StyledProperty<IEnumerable> ItemsSourceProperty =
AvaloniaProperty.Register<DataGrid, IEnumerable>(nameof(ItemsSource));
/// <summary>
/// Gets or sets a collection that is used to generate the content of the control.
/// </summary>
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<bool> AreRowDetailsFrozenProperty =
@ -713,7 +708,7 @@ namespace Avalonia.Controls
HorizontalScrollBarVisibilityProperty,
VerticalScrollBarVisibilityProperty);
ItemsProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.OnItemsPropertyChanged(e));
ItemsSourceProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.OnItemsSourcePropertyChanged(e));
CanUserResizeColumnsProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.OnCanUserResizeColumnsChanged(e));
ColumnWidthProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.OnColumnWidthChanged(e));
FrozenColumnCountProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.OnFrozenColumnCountChanged(e));
@ -816,10 +811,10 @@ namespace Avalonia.Controls
}
/// <summary>
/// ItemsProperty property changed handler.
/// ItemsSourceProperty property changed handler.
/// </summary>
/// <param name="e">The event arguments.</param>
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;
}

2
src/Avalonia.Controls.DataGrid/DataGridBoundColumn.cs

@ -25,7 +25,7 @@ namespace Avalonia.Controls
/// </summary>
//TODO Binding
[AssignBinding]
[InheritDataTypeFromItems(nameof(DataGrid.Items), AncestorType = typeof(DataGrid))]
[InheritDataTypeFromItems(nameof(DataGrid.ItemsSource), AncestorType = typeof(DataGrid))]
public virtual IBinding Binding
{
get

4
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<T>
if (_dataType == null && _owner.Items != null)
if (_dataType == null && _owner.ItemsSource != null)
{
_dataType = _owner.Items.GetItemType();
_dataType = _owner.ItemsSource.GetItemType();
}
return _dataType;
}

4
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
/// <remarks>
/// If this property is <see langword="null"/> the column is read-only.
/// </remarks>
[InheritDataTypeFromItems(nameof(DataGrid.Items), AncestorType = typeof(DataGrid))]
[InheritDataTypeFromItems(nameof(DataGrid.ItemsSource), AncestorType = typeof(DataGrid))]
public IDataTemplate CellEditingTemplate
{
get => _cellEditingCellTemplate;

2
src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml

@ -51,7 +51,7 @@
<DataGrid
x:Name="DataGrid"
Items="{Binding PropertiesView}"
ItemsSource="{Binding PropertiesView}"
Grid.Row="2"
BorderThickness="0"
RowBackground="Transparent"

2
tests/Avalonia.LeakTests/ControlTests.cs

@ -51,7 +51,7 @@ namespace Avalonia.LeakTests
{
Content = new DataGrid
{
Items = _observableCollection
ItemsSource = _observableCollection
}
};

Loading…
Cancel
Save