.NET MAUI DataGrid Empty Template
The .NET MAUI DataGrid control provides the ability to specify a template when the ItemsSource
is null or collection is empty.
It exposes the following properties:
EmptyContentTemplate
(DataTemplate
)—Defines the content of the view which is shown when in the view has no items.-
EmptyContentDisplayMode
—Defines the modes for displaying empty content. The property have two modes:-
ItemsSourceNull
—Displays the empty content view only when theItemsSource
is null. -
ItemsSourceNullOrEmpty
—Displays the empty content view whenItemsSource
is null or when the source is empty(has zero items).
-
Example:
1. Add DataGrid definition in XAML:
<telerik:RadDataGrid x:Name="dataGrid"
EmptyContentTemplate="{StaticResource EmptyContentTemplate}"/>
2. Add DataTemplate
Resources:
<ResourceDictionary>
<DataTemplate x:Key="EmptyContentTemplate">
<Label Margin="10" TextColor="Black" HorizontalOptions="Center" Text="No data to display"/>
</DataTemplate>
</ResourceDictionary>