Pergunta

Como faço para explicar algo como 'dofilter' System.Windows.Controls.ItemCollection?

Eu configuro sua propriedade Filter para um predicado. Coloquei um ponto de interrupção no predicado, ele só chega lá quando o itemScollection é inicializado, quando eu chamo m_itemscollection.Refresh () não é.

Foi útil?

Solução

Existem várias situações em que .refresh () não funciona, mas isso funciona:

collection.Filter = collection.Filter;

Eu encontrei isso há vários meses. Aparentemente, há um bug que impede o itemScontrol de passar de maneira confiável na chamada refresh () em determinadas situações. Não investigei os detalhes.

Outras dicas

O motivo do motivo às vezes não funciona é por causa desse código usado no 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;
        }
    } 

O filtro está sendo definido na visualização de coleção subjacente, em vez da própria scollection.

E então o método de atualização base não chama de fazer nada para _collectionView, então a atualização não faz nada!

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

Desculpe responder a uma pergunta antiga, mas senti que valeu a pena esclarecer.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top