Does anyone know how to add default content to an empty datagrid or listbox? Such as "No Results Returned" or something along those lines.
Default Content for Empty Datagrid or Listbox in WPF
146 views Asked by Edd At
2
There are 2 answers
0
On
<Style.Triggers>
<DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}" Value="0">
<Setter Property="CanUserSortColumns" Value="False" />
<Setter Property="Background">
<Setter.Value>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<TextBlock Text="We did't find any matching records for your group..." FontSize="14" FontWeight="SemiBold" Foreground="LightCoral"/>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
This is what I have found and was able to to test it. Thanks to anyone who tried to help.
You can do something like this, where the
ListBox
is Hidden and an associated errorGrid
is displayed instead. The benefit of this approach is that it is a bit more flexible, as you have an entireGrid
to use instead of aVisualBrush
.