Skip to content

Commit 0b7245a

Browse files
committed
feat: Add empty state support
1 parent 0218297 commit 0b7245a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

SimpleDataGrid.Example/MainWindow.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Title="MainWindow" Height="450" Width="800">
1212
<Window.Resources>
1313
<converters:ItemCountConverter x:Key="ItemCountConverter"/>
14+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
1415
</Window.Resources>
1516
<Window.DataContext>
1617
<local:MainViewModel />
@@ -56,6 +57,13 @@
5657

5758
<controls:PagedDataGrid x:Name="PagedDataGrid" Grid.Row="1" PagedSource="{Binding People}" AutoGenerateColumns="True" />
5859

60+
<Grid Grid.Row="1" Background="#AAFFFFFF" Visibility="{Binding People.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}">
61+
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
62+
<TextBlock Text="No items found." FontSize="24" FontWeight="Bold" Margin="0,0,0,10"/>
63+
<TextBlock Text="Try clearing your filters or search terms." FontSize="14" TextAlignment="Center"/>
64+
</StackPanel>
65+
</Grid>
66+
5967
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
6068
<Button Content="First" Click="FirstButton_Click" Margin="5" IsEnabled="{Binding People.HasPrevious}"/>
6169
<Button Content="Previous" Click="PreviousButton_Click" Margin="5" IsEnabled="{Binding People.HasPrevious}"/>

SimpleDataGrid/Pagination/PagedCollection.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ private static string WildcardToRegex(string pattern)
248248
/// </summary>
249249
public int TotalItems => _filtered.Count;
250250

251+
/// <summary>
252+
/// Gets a value indicating whether the filtered collection is empty.
253+
/// </summary>
254+
public bool IsEmpty => _filtered.Count == 0;
255+
256+
/// <summary>
257+
/// Gets a value indicating whether the filtered collection has any items.
258+
/// </summary>
259+
public bool HasItems => _filtered.Count > 0;
260+
261+
/// <summary>
262+
/// Gets a value indicating whether the original source collection is empty.
263+
/// </summary>
264+
public bool IsSourceEmpty => _source.Count == 0;
265+
251266
/// <summary>
252267
/// Gets a value indicating whether there is a next page.
253268
/// </summary>
@@ -347,6 +362,9 @@ private void RaiseAllChanged()
347362
OnPropertyChanged(nameof(TotalPages));
348363
OnPropertyChanged(nameof(HasNext));
349364
OnPropertyChanged(nameof(HasPrevious));
365+
OnPropertyChanged(nameof(IsEmpty));
366+
OnPropertyChanged(nameof(HasItems));
367+
OnPropertyChanged(nameof(IsSourceEmpty));
350368
}
351369

352370
/// <summary>

0 commit comments

Comments
 (0)