explicity call itemscollection.filterを呼び出すにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/2249576

質問

「Dofilter」のようなものと呼び出すにはどうすればよいですか System.Windows.Controls.ItemCollection?

フィルタープロパティを述語に設定します。私は述語にブレークポイントを配置しましたが、項目コレクションが初期化されたときにのみ、m_itemscollection.refresh()ではありません。

役に立ちましたか?

解決

.refresh()が機能しないいくつかの状況がありますが、これは次のとおりです。

collection.Filter = collection.Filter;

私は数ヶ月前にこれに出くわしました。どうやら、特定の状況では、ItemsControlが更新()コールを確実に渡さないようにするバグがあるようです。詳細は調査していません。

他のヒント

リフレッシュが時々機能しない理由は、このコードが項目コレクションで使用されているためです。

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

フィルターは、アイテムコレクション自体ではなく、基礎となるコレクションビューに設定されています。

そして、ベース更新方法は実際には何もしません _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();
    }  

古い質問に答えて申し訳ありませんが、明確にする価値があると感じました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top