ICollectionView不能与我的班级一起工作

时间:2018-06-07 13:51:43

标签: wpf vb.net xaml observable collectionview

我尝试使用Observable Collection过滤ICollectionView。 如果我的Observable来自string类型,则其工作原理如下:

我的Observable

   Private Property _annotationList As ObservableCollection(Of String) = New ObservableCollection(Of String)
   Public Property AnnotationList As ObservableCollection(Of String)
      Get
         Return _annotationList
      End Get
      Set(value As ObservableCollection(Of String))
         _annotationList = value
         OnPropertyChanged()
      End Set
   End Property

ICollectionView

  Public ReadOnly Property FilteredList As ICollectionView
      Get
         Dim source = CollectionViewSource.GetDefaultView(AnnotationList)
         source.Filter = Function(x) Check(x)
         Return source
         OnPropertyChanged()
      End Get
   End Property

过滤器:

 Public Function Check(x As String) As Boolean
      If Filter() = String.Empty Then
         Return True
      End If
      If x.StartsWith(Filter) Then
         Return True
      End If
      Return False
   End Function

最后是Binding

    <dxe:ListBoxEdit
                                    Grid.Row="1"
                                    IncrementalSearch="False"
                                    ItemsSource="{Binding FilteredList, RelativeSource={RelativeSource TemplatedParent}}"
                                    Name="lbComments"
                                    AllowLiveDataShaping="False"
                                    Width="275"
                                    MaxWidth="275"
                                    Padding="5,0,5,0">
                 <!--Some Controls-->
</dxe:ListBoxEdit>

但如果我将Observable更改为PdfMarkupAnnotationDataWrapper这是我的班级,则列表框只是空的。

这是班级:

Public Class PdfMarkupAnnotationDataWrapper
   Inherits PropertyChanged
#Region "Commands"

   Private _showTags As ICommand = New DelegateCommandsNotGen(Sub(lbComments As ListBoxEdit) ChangeTagVis(lbComments))
   Public ReadOnly Property ShowTags As ICommand
      Get
         Return _showTags
      End Get
   End Property
#End Region
#Region "Properties"
   Private _author As String
   Public Property Author As String
      Get
         Return _author
      End Get
      Set(ByVal value As String)
         _author = value
         OnPropertyChanged()
      End Set
   End Property

   Private _content As String = ""
   Public Property Content As String
      Get
         Return _content
      End Get
      Set(value As String)
         _content = value
         OnPropertyChanged()
      End Set
   End Property

   Private _isTextBoxVis As Boolean = False
   <XmlIgnoreAttribute()> Public Property IsTextBoxVis As Boolean
      Get
         Return _isTextBoxVis
      End Get
      Set(ByVal value As Boolean)
         _isTextBoxVis = value
         OnPropertyChanged()
      End Set
   End Property
#End Region

我还将过滤器更改为:

Public ReadOnly Property FilteredList As ICollectionView
      Get
         Dim source = CollectionViewSource.GetDefaultView(AnnotationList)
         source.Filter = Function(x As PdfMarkupAnnotationDataWrapper) Check(x.Content)
         Return source
         OnPropertyChanged()
      End Get
   End Property

0 个答案:

没有答案