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
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
...全文
相关推荐
wpf data filter
wpf data filter control
WPF DataGrid仿Excel筛选:ICollectionView.Filter实战指南
WPF DataGrid的筛选功能本质依赖ICollectionView抽象层,而非直接操作ItemsSource。理解ICollectionView的Filter、SortDescriptions和GroupDescriptions协同机制,是实现稳定排序、分组与多列AND筛选的前提。通过动态ExpressionTree构建类型安全的Predicate<object>委托,可支持运行时列名、条件运算符(如Contains、GreaterThan)及多数据类型(string/int/DateTime)的灵活
wpf DataGrid分组、排序、筛选
针对 DataGrid 控件,对数据进行分组、排序和筛选....
具有过滤和排序功能的WinRT CollectionView类
本文介绍了一个ICollectionView类,该类支持过滤和排序。
在MVVM设置中对WPF ListView进行排序和过滤
一个简单的WPF应用程序,通过MVVM框架中的排序和过滤实现了主从设置。


