Comment puis-je appeler explicitement des articles Collection.Filter?
-
20-09-2019 - |
Question
Comment puis-je explicityl appelle quelque chose comme 'DoFilter' sur
La solution Il y a plusieurs situations où .Refresh () ne fonctionne pas, mais cela ne: Je suis tombé sur ce il y a plusieurs mois. Apparemment, il y a un bug qui empêche ItemsControl de passer de manière fiable vers le bas l'appel Refresh () dans certaines situations. Je ne l'ai pas étudié les détails. collection.Filter = collection.Filter;
Autres conseils
La raison Actualiser ne fonctionne pas est parfois à cause de ce code étant utilisé sur le 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;
}
}
Le filtre se prépare sur la vue de collection sous-jacente, plutôt que le ItemsCollection lui-même.
Et puis la base méthode Refresh ne remet pas réellement faire quoi que ce soit à _collectionView
, si refresh ne fait rien!
/// <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();
}
Désolé pour répondre à la vieille question, mais a estimé qu'il était utile de préciser.