Reputation: 181
If the Bounded List is empty I want to display a default message in the listbox like "No Items Present"
Upvotes: 3
Views: 4184
Reputation: 21873
use this method which is using Datatrigger of the listbox .
WPF listbox empty datatemplate
Upvotes: 1
Reputation: 7601
You should a textBlock on top of the listbox, and bind its visibility to the collection also, using a converter that would convert null to Visibility.Collapsed.
<Grid>
<ListBox ItemsSource="{Binding TheItems}" />
<TextBlock Text="No Items Found"
Visibility="{Binding TheItems, Converter={StaticResource TheConverter}}" />
</Grid>
and the converter:
public class NullToInvisibleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value==null ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Upvotes: 4