我想您将在该枢轴项目中有一个收藏夹列表,因此我的方法是将枢轴项目的可见性绑定到列表的 isEmpty 属性。
例如,视图将是
<PivotItem
Visibility="{Binding IsNotEmpty,
Converter={StaticResource VisibilityConverter}}"/>
并在视图模型中
ICollectionView ItemsSource;
...
public bool IsNotEmpty(){
return !ItemsSource.IsEmpty;
}
最后,转换器
public class BooleanToVisibilityConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value == null)
return Visibility.Collapsed;
var isVisible = (bool)value;
return isVisible ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var visiblity = (Visibility)value;
return visiblity == Visibility.Visible;
}}
从有用的转换器获得的转换器