Skip to content

Commit 09c139d

Browse files
committed
documentation
1 parent 6896a96 commit 09c139d

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

SimpleDataGrid/Controls/PageDataGrid.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
21
using SimpleDataGrid.Pagination;
32
using System.Windows;
43
using System.Windows.Controls;
54

65
namespace SimpleDataGrid.Controls;
76

7+
/// <summary>
8+
/// A DataGrid that supports pagination through a <see cref="PagedCollection{T}"/>.
9+
/// </summary>
10+
/// <typeparam name="T">The type of items in the collection.</typeparam>
811
public class PagedDataGrid<T> : DataGrid
912
{
13+
/// <summary>
14+
/// Identifies the <see cref="PagedSource"/> dependency property.
15+
/// </summary>
1016
public static readonly DependencyProperty PagedSourceProperty =
1117
DependencyProperty.Register(nameof(PagedSource), typeof(PagedCollection<T>), typeof(PagedDataGrid<T>),
1218
new PropertyMetadata(null, OnPagedSourceChanged));
1319

20+
/// <summary>
21+
/// Gets or sets the paged collection that this grid displays.
22+
/// </summary>
1423
public PagedCollection<T>? PagedSource
1524
{
1625
get => (PagedCollection<T>)GetValue(PagedSourceProperty);
@@ -31,4 +40,4 @@ private static void OnPagedSourceChanged(DependencyObject d, DependencyPropertyC
3140
};
3241
}
3342
}
34-
}
43+
}

SimpleDataGrid/Pagination/PagedCollection.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
12
using System.ComponentModel;
23

34
namespace SimpleDataGrid.Pagination;
45

6+
/// <summary>
7+
/// Represents a collection of items that can be paged, filtered, and searched.
8+
/// </summary>
9+
/// <typeparam name="T">The type of items in the collection.</typeparam>
510
public class PagedCollection<T> : INotifyPropertyChanged
611
{
712
private readonly int _pageSize;
@@ -13,30 +18,50 @@ public class PagedCollection<T> : INotifyPropertyChanged
1318
private Func<T, string>? _searchSelector;
1419
private string? _searchTerm;
1520

21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="PagedCollection{T}"/> class.
23+
/// </summary>
24+
/// <param name="pageSize">The number of items to display per page.</param>
1625
public PagedCollection(int pageSize = 50)
1726
{
1827
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(pageSize);
1928
this._pageSize = pageSize;
2029
}
2130

31+
/// <summary>
32+
/// Sets the source collection.
33+
/// </summary>
34+
/// <param name="items">The source collection.</param>
2235
public void SetSource(IReadOnlyList<T> items)
2336
{
2437
_source = items ?? throw new ArgumentNullException(nameof(items));
2538
ApplyFiltering();
2639
}
2740

41+
/// <summary>
42+
/// Adds a filter to the collection.
43+
/// </summary>
44+
/// <param name="filter">The filter to add.</param>
2845
public void AddFilter(Func<T, bool> filter)
2946
{
3047
_filters.Add(filter);
3148
ApplyFiltering();
3249
}
3350

51+
/// <summary>
52+
/// Clears all filters from the collection.
53+
/// </summary>
3454
public void ClearFilters()
3555
{
3656
_filters.Clear();
3757
ApplyFiltering();
3858
}
3959

60+
/// <summary>
61+
/// Sets the search criteria for the collection.
62+
/// </summary>
63+
/// <param name="selector">A function that returns the string representation of the object to search.</param>
64+
/// <param name="term">The search term.</param>
4065
public void SetSearch(Func<T, string> selector, string? term)
4166
{
4267
_searchSelector = selector;
@@ -65,16 +90,35 @@ private void ApplyFiltering()
6590
RaiseAllChanged();
6691
}
6792

93+
/// <summary>
94+
/// Gets the items on the current page.
95+
/// </summary>
6896
public IReadOnlyList<T> CurrentPageItems =>
6997
[.. _filtered.Skip(_currentPage * _pageSize).Take(_pageSize)];
7098

99+
/// <summary>
100+
/// Gets the current page number.
101+
/// </summary>
71102
public int CurrentPage => _currentPage + 1;
72103

104+
/// <summary>
105+
/// Gets the total number of pages.
106+
/// </summary>
73107
public int TotalPages => (int)Math.Ceiling((double)_filtered.Count / _pageSize);
74108

109+
/// <summary>
110+
/// Gets a value indicating whether there is a next page.
111+
/// </summary>
75112
public bool HasNext => _currentPage < TotalPages - 1;
113+
114+
/// <summary>
115+
/// Gets a value indicating whether there is a previous page.
116+
/// </summary>
76117
public bool HasPrevious => _currentPage > 0;
77118

119+
/// <summary>
120+
/// Moves to the next page.
121+
/// </summary>
78122
public void NextPage()
79123
{
80124
if (HasNext)
@@ -87,6 +131,9 @@ public void NextPage()
87131
}
88132
}
89133

134+
/// <summary>
135+
/// Moves to the previous page.
136+
/// </summary>
90137
public void PreviousPage()
91138
{
92139
if (HasPrevious)
@@ -108,7 +155,10 @@ private void RaiseAllChanged()
108155
OnPropertyChanged(nameof(HasPrevious));
109156
}
110157

158+
/// <summary>
159+
/// Occurs when a property value changes.
160+
/// </summary>
111161
public event PropertyChangedEventHandler? PropertyChanged;
112162
private void OnPropertyChanged(string name) =>
113163
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
114-
}
164+
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0-windows</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<UseWPF>true</UseWPF>
8+
9+
<PackageId>SimpleDataGrid</PackageId>
10+
<Version>1.0.0</Version>
11+
<Authors>Your Name</Authors>
12+
<Company>Your Company</Company>
13+
<PackageDescription>A simple DataGrid that supports pagination, filtering, and searching.</PackageDescription>
14+
<RepositoryUrl>https://github.com/your-username/SimpleDataGrid</RepositoryUrl>
15+
<PackageTags>wpf datagrid pagination filtering searching</PackageTags>
16+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
817
</PropertyGroup>
918

10-
</Project>
19+
</Project>

0 commit comments

Comments
 (0)