如何明确要求项目Collection.Filter?
-
20-09-2019 - |
题
我如何explicityl称像 '的doFilter' 上的 System.Windows.Controls.ItemCollection
?
我设置了它的过滤器属性设置为一个谓语。我放置一个断点在谓词,它到达那里只有当ItemsCollection被初始化时,当我打电话m_ItemsCollection.Refresh()不是这样的。
解决方案
有几种情况下.REFRESH()不工作,但这样做:
collection.Filter = collection.Filter;
我就遇到了这个几个月前。显然有是保持从ItemsControl的可靠传承在某些情况下刷新()调用的错误。我还没有研究的细节。
其他提示
原因刷新有时不工作就是因为这个代码在ItemsCollection被使用:
/// <summary>
/// Set/get a filter callback to filter out items in collection.
/// This property will always accept a filter, but the collection view for the
/// underlying ItemsSource may not actually support filtering.
/// Please check <seealso cref="CanFilter"/>
/// </summary>
/// <exception cref="NotSupportedException">
/// Collections assigned to ItemsSource may not support filtering and could throw a NotSupportedException.
/// Use <seealso cref="CanFilter"/> property to test if filtering is supported before assigning
/// a non-null Filter value.
/// </exception>
public override Predicate<object> Filter
{
get
{
return (EnsureCollectionView()) ? _collectionView.Filter : MyFilter;
}
set
{
MyFilter = value;
if (_collectionView != null)
_collectionView.Filter = value;
}
}
在过滤器是越来越设置底层集合视图,而不是ItemsCollection本身。
然后是基本刷新方法实际上并没有打电话做任何_collectionView
,所以刷新什么也不做!
/// <summary>
/// Re-create the view, using any <seealso cref="SortDescriptions"/> and/or <seealso cref="Filter"/>.
/// </summary>
public virtual void Refresh()
{
IEditableCollectionView ecv = this as IEditableCollectionView;
if (ecv != null && (ecv.IsAddingNew || ecv.IsEditingItem))
throw new InvalidOperationException(SR.Get(SRID.MemberNotAllowedDuringAddOrEdit, "Refresh"));
RefreshInternal();
}
抱歉到老问题做出响应,但认为这是值得澄清。
不隶属于 StackOverflow