|
| 1 | + |
| 2 | +# SimpleDataGrid |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +A simple DataGrid for WPF that supports pagination, filtering, and searching. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +* **Pagination:** Easily page through large datasets. |
| 11 | +* **Filtering:** Filter data based on custom criteria. |
| 12 | +* **Searching:** Search for data using strings or wildcards. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +1. Install the `SimpleDataGrid` NuGet package. |
| 17 | +2. Add the `PagedDataGrid` control to your XAML. |
| 18 | +3. Create a `PagedCollection` and bind it to the `PagedSource` property of the `PagedDataGrid`. |
| 19 | + |
| 20 | +```xaml |
| 21 | +<Window x:Class="SimpleDataGrid.Example.MainWindow" |
| 22 | + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| 23 | + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 24 | + xmlns:local="clr-namespace:SimpleDataGrid.Example" |
| 25 | + mc:Ignorable="d" |
| 26 | + Title="MainWindow" Height="450" Width="800"> |
| 27 | + <Window.DataContext> |
| 28 | + <local:MainViewModel /> |
| 29 | + </Window.DataContext> |
| 30 | + <Grid> |
| 31 | + <Grid.RowDefinitions> |
| 32 | + <RowDefinition Height="Auto" /> |
| 33 | + <RowDefinition Height="*" /> |
| 34 | + <RowDefinition Height="Auto" /> |
| 35 | + </Grid.RowDefinitions> |
| 36 | + |
| 37 | + <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5"> |
| 38 | + <TextBox x:Name="SearchTextBox" Width="200" Margin="5" /> |
| 39 | + <Button Content="Search" Click="SearchButton_Click" Margin="5" /> |
| 40 | + <CheckBox x:Name="WildcardCheckBox" Content="Use Wildcards" VerticalAlignment="Center" Margin="5" /> |
| 41 | + </StackPanel> |
| 42 | + |
| 43 | + <local:PersonPagedDataGrid x:Name="PagedDataGrid" Grid.Row="1" PagedSource="{Binding People}" AutoGenerateColumns="True" /> |
| 44 | + |
| 45 | + <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center"> |
| 46 | + <Button Content="Previous" Click="PreviousButton_Click" Margin="5" /> |
| 47 | + <TextBlock Text="{Binding People.CurrentPage}" VerticalAlignment="Center" Margin="5" /> |
| 48 | + <TextBlock Text="/" VerticalAlignment="Center" /> |
| 49 | + <TextBlock Text="{Binding People.TotalPages}" VerticalAlignment="Center" Margin="5" /> |
| 50 | + <Button Content="Next" Click="NextButton_Click" Margin="5" /> |
| 51 | + </StackPanel> |
| 52 | + </Grid> |
| 53 | +</Window> |
| 54 | +``` |
| 55 | + |
| 56 | +```csharp |
| 57 | +public partial class MainWindow : Window |
| 58 | +{ |
| 59 | + public MainWindow() |
| 60 | + { |
| 61 | + InitializeComponent(); |
| 62 | + } |
| 63 | + |
| 64 | + private void PreviousButton_Click(object sender, RoutedEventArgs e) |
| 65 | + { |
| 66 | + var viewModel = (MainViewModel)DataContext; |
| 67 | + viewModel.People.PreviousPage(); |
| 68 | + } |
| 69 | + |
| 70 | + private void NextButton_Click(object sender, RoutedEventArgs e) |
| 71 | + { |
| 72 | + var viewModel = (MainViewModel)DataContext; |
| 73 | + viewModel.People.NextPage(); |
| 74 | + } |
| 75 | + |
| 76 | + private void SearchButton_Click(object sender, RoutedEventArgs e) |
| 77 | + { |
| 78 | + var viewModel = (MainViewModel)DataContext; |
| 79 | + viewModel.People.SetSearch(p => p.Name, SearchTextBox.Text, WildcardCheckBox.IsChecked == true); |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## License |
| 85 | + |
| 86 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments