Browse Source

Implement IList on DataGridCollectionView. (#13313)

Fixes #11586
pull/13323/head
Steven Kirk 3 years ago
committed by GitHub
parent
commit
87ffbfc089
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs
  2. 7
      src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs

18
src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

@ -54,7 +54,7 @@ namespace Avalonia.Collections
/// <summary>
/// DataGrid-readable view over an IEnumerable.
/// </summary>
public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridEditableCollectionView, INotifyPropertyChanged
public sealed class DataGridCollectionView : IDataGridCollectionView, IDataGridEditableCollectionView, IList, INotifyPropertyChanged
{
/// <summary>
/// Since there's nothing in the un-cancelable event args that is mutable,
@ -1153,6 +1153,17 @@ namespace Avalonia.Collections
get { return GetItemAt(index); }
}
bool IList.IsFixedSize => false;
bool IList.IsReadOnly => true;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get => this[index];
set => throw new NotSupportedException();
}
/// <summary>
/// Add a new item to the underlying collection. Returns the new item.
/// After calling AddNew and changing the new item as desired, either
@ -3981,6 +3992,11 @@ namespace Avalonia.Collections
}
}
int IList.Add(object value) => throw new NotSupportedException();
void IList.Clear() => throw new NotSupportedException();
void IList.Insert(int index, object value) => throw new NotSupportedException();
void ICollection.CopyTo(Array array, int index) => InternalList.CopyTo(array, index);
/// <summary>
/// Creates a comparer class that takes in a CultureInfo as a parameter,
/// which it will use when comparing strings.

7
src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs

@ -193,18 +193,17 @@ namespace Avalonia.Controls
}
}
/// <summary>Try get number of DataSource itmes.</summary>
/// <summary>Try get number of DataSource items.</summary>
/// <param name="allowSlow">When "allowSlow" is false, method will not use Linq.Count() method and will return 0 or 1 instead.</param>
/// <param name="getAny">If "getAny" is true, method can use Linq.Any() method to speedup.</param>
/// <param name="count">number of DataSource itmes.</param>
/// <returns>true if able to retrieve number of DataSource itmes; otherwise, false.</returns>
/// <param name="count">number of DataSource items.</param>
/// <returns>true if able to retrieve number of DataSource items; otherwise, false.</returns>
internal bool TryGetCount(bool allowSlow, bool getAny, out int count)
{
bool result;
(result, count) = DataSource switch
{
ICollection collection => (true, collection.Count),
DataGridCollectionView cv => (true, cv.Count),
IEnumerable enumerable when allowSlow && !getAny => (true, enumerable.Cast<object>().Count()),
IEnumerable enumerable when getAny => (true, enumerable.Cast<object>().Any() ? 1 : 0),
_ => (false, 0)

Loading…
Cancel
Save