ICollectionView.Filter 怎么写呀?

liyiding23 liyiding23 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在做一个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
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
liyiding23
VB 16,718 成员 110,520 内容