更新过滤器后ICollectionView null异常

时间:2018-06-13 08:59:47

标签: vb.net filter observable

我的ICollectionView就像这样Observable

Public cvAnnotations As CollectionViewSource = New CollectionViewSource()

Private Property _annotationList As ObservableCollection(Of PdfMarkupAnnotationDataWrapper)
Public Property AnnotationList As ObservableCollection(Of PdfMarkupAnnotationDataWrapper)
          Get
             Return _annotationList
          End Get
          Set(value As ObservableCollection(Of PdfMarkupAnnotationDataWrapper))
             _annotationList = value
             cvAnnotations.Source = _annotationList
             FilteredList = cvAnnotations.View
             OnPropertyChanged()
          End Set
       End Property

       Private Property _filteredList As ICollectionView
       Public Property FilteredList As ICollectionView
          Get
             cvAnnotations.View.Filter = Function(x As PdfMarkupAnnotationDataWrapper) FilterAnnotations(x)
             _filteredList = cvAnnotations.View
             Return _filteredList
          End Get
          Set(value As ICollectionView)
             _filteredList = value
             OnPropertyChanged()
          End Set
       End Property

现在textbox中的XAML绑定到属性Filter,当用户输入内容时,该属性应更新ICollectionView的过滤器:

    Private Property _filter As String
   Public Property Filter As String
      Get
         Return _filter
      End Get
      Set(value As String)
         'Here it is null after a new item was added to the Observable
         FilteredList.Refresh()
         _filter = value
         OnPropertyChanged()
      End Set
   End Property

这项工作正常,直到我将一个项目添加到ICollectionView的来源(observableCollection AnnotationList

因此,在添加新项目然后在过滤器文本框中输入内容后,ICollectionViewnull

0 个答案:

没有答案