ObservableCollection的可见性 IValueConverter
我想创建一个可见性转换器,如果可观察集合为空或为空,它会显示内容。由于此转换器将在许多屏幕上使用,因此每个集合将保存不同的类型 (T)。
如何获取对未知类型的 ObservableCollection 的引用。这是我到目前为止所拥有的:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) return Visibility.Visible;
if (value is ObservableCollection<object>)
{
var col = value as ObservableCollection<object>;
return col.Count > 0 ? Visibility.Hidden : Visibility.Visible;
}
return Binding.DoNothing;
}
I'd like to create a visibility converter which displays content if an observablecollection is empty or null. As this converter will be used on many screens, each collection will hold a different type (T).
How do I get a reference to the ObservableCollection of unknown type. This is what I have so far:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) return Visibility.Visible;
if (value is ObservableCollection<object>)
{
var col = value as ObservableCollection<object>;
return col.Count > 0 ? Visibility.Hidden : Visibility.Visible;
}
return Binding.DoNothing;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不必这样做。只需转换为
ICollection
并获取其Count
。You don't have to. Just cast to
ICollection
and get itsCount
.