Browse Source

feat(DataGrid): make IDataGridCollectionViewFactory and IDataGridCollectionView, Add DP CollectionView (#14744)

* feat(DataGrid): make IDataGridCollectionViewFactory and IDataGridCollectionView public

* feat(DataGrid): Add CollectionView DP

* fix: nits
pull/14761/head
workgroupengineering 3 years ago
committed by GitHub
parent
commit
04f43a5da6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs
  2. 2
      src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs
  3. 31
      src/Avalonia.Controls.DataGrid/DataGrid.cs

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

@ -44,7 +44,7 @@ namespace Avalonia.Collections
} }
/// <summary>Defines a method that enables a collection to provide a custom view for specialized sorting, filtering, grouping, and currency.</summary> /// <summary>Defines a method that enables a collection to provide a custom view for specialized sorting, filtering, grouping, and currency.</summary>
internal interface IDataGridCollectionViewFactory public interface IDataGridCollectionViewFactory
{ {
/// <summary>Returns a custom view for specialized sorting, filtering, grouping, and currency.</summary> /// <summary>Returns a custom view for specialized sorting, filtering, grouping, and currency.</summary>
/// <returns>A custom view for specialized sorting, filtering, grouping, and currency.</returns> /// <returns>A custom view for specialized sorting, filtering, grouping, and currency.</returns>

2
src/Avalonia.Controls.DataGrid/Collections/IDataGridCollectionView.cs

@ -66,7 +66,7 @@ namespace Avalonia.Collections
} }
/// <summary>Enables collections to have the functionalities of current record management, custom sorting, filtering, and grouping.</summary> /// <summary>Enables collections to have the functionalities of current record management, custom sorting, filtering, and grouping.</summary>
internal interface IDataGridCollectionView : IEnumerable, INotifyCollectionChanged public interface IDataGridCollectionView : IEnumerable, INotifyCollectionChanged
{ {
/// <summary>Gets or sets the cultural information for any operations of the view that may differ by culture, such as sorting.</summary> /// <summary>Gets or sets the cultural information for any operations of the view that may differ by culture, such as sorting.</summary>
/// <returns>The culture information to use during culture-sensitive operations. </returns> /// <returns>The culture information to use during culture-sensitive operations. </returns>

31
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -716,6 +716,17 @@ namespace Avalonia.Controls
set { SetValue(RowDetailsVisibilityModeProperty, value); } set { SetValue(RowDetailsVisibilityModeProperty, value); }
} }
public static readonly DirectProperty<DataGrid, IDataGridCollectionView> CollectionViewProperty =
AvaloniaProperty.RegisterDirect<DataGrid, IDataGridCollectionView>(nameof(CollectionView),
o => o.CollectionView);
/// <summary>
/// Gets current <see cref="IDataGridCollectionView"/>.
/// </summary>
public IDataGridCollectionView CollectionView =>
DataConnection.CollectionView;
static DataGrid() static DataGrid()
{ {
AffectsMeasure<DataGrid>( AffectsMeasure<DataGrid>(
@ -837,6 +848,8 @@ namespace Avalonia.Controls
{ {
Debug.Assert(DataConnection != null); Debug.Assert(DataConnection != null);
var oldCollectionView = DataConnection.CollectionView;
var oldValue = (IEnumerable)e.OldValue; var oldValue = (IEnumerable)e.OldValue;
var newItemsSource = (IEnumerable)e.NewValue; var newItemsSource = (IEnumerable)e.NewValue;
@ -865,14 +878,24 @@ namespace Avalonia.Controls
// Wrap an IEnumerable in an ICollectionView if it's not already one // Wrap an IEnumerable in an ICollectionView if it's not already one
bool setDefaultSelection = false; bool setDefaultSelection = false;
if (newItemsSource != null && !(newItemsSource is IDataGridCollectionView)) if (newItemsSource is IDataGridCollectionView newCollectionView)
{ {
DataConnection.DataSource = DataGridDataConnection.CreateView(newItemsSource); setDefaultSelection = true;
} }
else else
{ {
DataConnection.DataSource = newItemsSource; newCollectionView = newItemsSource is not null
setDefaultSelection = true; ? DataGridDataConnection.CreateView(newItemsSource)
: default;
}
DataConnection.DataSource = newCollectionView;
if (oldCollectionView != DataConnection.CollectionView)
{
RaisePropertyChanged(CollectionViewProperty,
oldCollectionView,
newCollectionView);
} }
if (DataConnection.DataSource != null) if (DataConnection.DataSource != null)

Loading…
Cancel
Save