If the Bounded List is empty I want to display a default me开发者_开发技巧ssage in the listbox like "No Items Present"
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();
}
}
use this method which is using Datatrigger of the listbox .
WPF listbox empty datatemplate
精彩评论