我有一个TreeView
使用,它ListCollectionView
具有自定义IComprarer
和实时调整功能以订购其子级。在TreeViewItem
视图中将当前选定的内容重新排序后,我希望TreeView
可以自动滚动到TreeViewItem
的新位置。但是,当ListCollectionView
应用新的排序时,我找不到找到通知的方法,并且我想要的行为似乎没有内置到中TreeViewControl
。
ListCollectionView
重新计算排序顺序时,有什么方法可以通知我吗?
我相信这次活动CollectionChanged
正是您所需要的。您可以执行以下操作:
((ICollectionView)yourListCollectionView).CollectionChanged += handler;
我们必须在此处强制转换的原因CollectionChanged
是作为INotifyPropertyChanged
(ICollectionView
继承自此接口的)成员的源代码实现的:
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
{
add {
CollectionChanged += value;
}
remove {
CollectionChanged -= value;
}
}
此实现是显式的。因此,该事件作为公共成员无法正常访问。要公开该成员,可以将实例强制转换为ICollectionView
或INotifyPropertyChanged
。
。当显式实现接口时,必须先将实例显式转换为该接口,然后才能访问该接口成员。
有关实现接口的示例:
public interface IA {
void Test();
}
//implicitly implement
public class A : IA {
public void Test() { ... }
}
var a = new A();
a.Test();//you can do this
//explicitly implement
public class A : IA {
void IA.Test() { ... } //note that there is no public and the interface name
// is required
}
var a = new A();
((IA)a).Test(); //this is how you do it.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句