ICollectionView.Filter 怎么写呀?
在做一个Filter 用C#的转过来
view.Filter += Me.FilterPredicate ' 这里出错
view.Filter -= Me.FilterPredicate '这里出错
'--------------------c#
ICollectionView view = CollectionViewSource.GetDefaultView(newValue);view.Filter += this.FilterPredicate;
'--------------------VB完整代码
Protected Overloads Overrides Sub OnItemsSourceChanged(ByVal oldValue As system.Collections.IEnumerable, ByVal newValue As System.Collections.IEnumerable)
If newValue IsNot Nothing Then
Dim view As ICollectionView = CollectionViewSource.GetDefaultView(newValue)
view.Filter += Me.FilterPredicate ' 这里出错
End If
If oldValue IsNot Nothing Then
Dim view As ICollectionView = CollectionViewSource.GetDefaultView(oldValue)
view.Filter -= Me.FilterPredicate '这里出错
End If
MyBase.OnItemsSourceChanged(oldValue, newValue)
End Sub
Private Function FilterPredicate(ByVal value As Object) As Boolean
' We don't like nulls.
If value Is Nothing Then
Return False
End If
' If there is no text, there's no reason to filter.
If Me.Text.Length = 0 Then
Return True
End If
Dim prefix As String = Me.Text
' If the end of the text is selected, do not mind it.
If Me.length > 0 AndAlso Me.start + Me.length = Me.Text.Length Then
prefix = prefix.Substring(0, Me.start)
End If
Return value.ToString().StartsWith(prefix, Not Me.IsCaseSensitive, CultureInfo.CurrentCulture)
End Function