开发者

How do I explicity call ItemsCollection.Filter?

How do I explicityl call开发者_JS百科 something like 'DoFilter' on System.Windows.Controls.ItemCollection?

I set up it's Filter property to a Predicate. I placed a breakpoint in the predicate, it reaches there only when the ItemsCollection is initialized, when I call m_ItemsCollection.Refresh() it's not.


There are several situations where .Refresh() doesn't work but this does:

collection.Filter = collection.Filter;

I ran into this several months ago. Apparently there is a bug that keeps ItemsControl from reliably passing down the Refresh() call in certain situations. I have not investigated the details.


The reason Refresh sometimes doesn't work is because of this code being used on the 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;
        }
    } 

The filter is getting set on the underlying collection view, rather than the ItemsCollection itself.

And then the base Refresh method doesn't actually call do anything to _collectionView, so refresh does nothing!

/// <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();
    }  

Sorry to respond to old question, but felt it was worth clarifying.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜