那怎麼樣?
<ListView.Triggers>
<DataTrigger Binding="{Binding FilteredTasks, Converter={StaticResource EmptyCollectionToBoolConverter}}" Value="true" TargetType="ListView">
<Setter Property="Header">
<Label Text="Ooops, there is nothing there."/>
</Setter>
</DataTrigger>
</ListView.Triggers>
和轉換器:
public class EmptyCollectionToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ICollection collection)
{
return collection.Count == 0;
}
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
沒有像'onDataBound'Event一個簡單的解決方案? –