Skip to content

Commit

Permalink
make PageCount read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Dec 29, 2023
1 parent 4fdda75 commit 01cf11c
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,7 @@ private void SortAndPaginate(SortData? sortData = null)
/// Gets or sets the page count for the DataGrid.
/// </summary>
public static readonly BindableProperty PageCountProperty =
BindablePropertyExtensions.Create<DataGrid, int>(1,
propertyChanged: (b, o, n) =>
{
if (o != n && b is DataGrid self && n > 0)
{
if (n > 1)
{
self._paginationStepper.IsEnabled = true;
self._paginationStepper.Maximum = n;
}
else
{
self._paginationStepper.IsEnabled = false;
}
}
});
BindablePropertyExtensions.Create<DataGrid, int>(1, BindingMode.OneWayToSource);

/// <summary>
/// Gets or sets the page size for the DataGrid.
Expand Down Expand Up @@ -1073,25 +1058,19 @@ public View NoDataView
/// </summary>
public int PageCount
{
get => (int)GetValue(PageCountProperty);
private set => SetValue(PageCountProperty, value);
}

#pragma warning restore CA2227 // Collection properties should be read only

internal IList<object>? InternalItems
{
get => _internalItems;
set
get => (int)_paginationStepper.Maximum;
private set
{
if (_internalItems != value)
if (value > 0)
{
_internalItems = value;
_collectionView.ItemsSource = _internalItems; // TODO: Are we using the most efficient CollectionChanged handling with observables?
_paginationStepper.Maximum = value;
_paginationStepper.IsEnabled = value > 1;
}
}
}

#pragma warning restore CA2227 // Collection properties should be read only

#endregion Properties

#region UI Methods
Expand Down

0 comments on commit 01cf11c

Please sign in to comment.