سؤال

كيف يمكنني أن أستكشف شيئا مثل "Dofilter" System.Windows.Controls.ItemCollection?

قمت بإعداد خاصية مرشحها إلى المسند. لقد وضعت نقطة توقف في المسند، فهي تصل إلى هناك فقط عند تهيئة OctionCollection، عندما اتصلت m_itemscollection.refresh () ليس كذلك.

هل كانت مفيدة؟

المحلول

هناك عدة حالات حيث .Refresh () لا يعمل ولكن هذا يفعل:

collection.Filter = collection.Filter;

ركضت في هذا منذ عدة أشهر. على ما يبدو هناك خطأ يبقي العناصر عند إجراء مكالمة من التحديث بشكل موثوق () في مواقف معينة. لم أصرح في التفاصيل.

نصائح أخرى

السبب في بعض الأحيان لا يعمل التحديث في بعض الأحيان بسبب هذا الرمز المستخدم في OutdoDCollection:

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

يتم تعيين المرشح على طريقة عرض المجموعة الأساسية، بدلا من conditionCollection نفسها.

ثم لا تتصل طريقة التحديث الأساسية في الواقع بأي شيء _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