wpf,CollectionViewSource,使用数据过滤 筛选 功能。
class TextListBoxVMpublic : ViewModelBase
{
public TextListBoxVMpublic()
{
var list = this.GetEmployees();
this.filteredEmploees = new CollectionViewSource();
this.filteredEmploees.Source = list;
this.filteredEmploees.Filter += this.EmployeeFilter;
} private CollectionViewSource filteredEmploees;
public CollectionViewSource FilteredEmploees
{
get { return filteredEmploees; }
set { filteredEmploees = value; }
} private string filterText = string.Empty;
public string FilterText
{
get { return filterText; }
set
{
filterText = value;
Notify("FilterText");
this.FilteredEmploees.View.Refresh();
}
} private void EmployeeFilter(object sender, FilterEventArgs e)
{
e.Accepted = this.EmployeeFilter(e.Item);
} private bool EmployeeFilter(object item)
{
var employee = item as Employee;
return employee != null && employee.Name.ToLower().Contains(this.FilterText.ToLower());
} private ObservableCollection<Employee> GetEmployees()
{
var list = new ObservableCollection<Employee>(); list.Add(new Employee { Name = "Huon Laprice", Position = "Events Assistant", Team = "Marketing", Office = "USA Office : Boston, MA", Address = "321 Jones Rd , Waltham, MA 04462", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image51.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Keiran Hughes", Position = "Trainee", Team = "Marketing", Office = "Canada Office: Toronto", Address = "110-556 Portage Ave. Winnipeg, R3B 5A7", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image52.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Swen Trommler", Position = "Brand Manager", Team = "Marketing", Office = "United Kingdom Office: London", Address = "15 Bedford Square London WC81C 15JA", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image53.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Valentino Lorenco", Position = "Brand Manager", Team = "Marketing", Office = "Canada Office: Toronto", Address = "110-556 Portage Ave. Winnipeg, R3B 5A7", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image55.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Linda Rodriges", Position = "Customer Advocate", Team = "Marketing", Office = "USA Office : San Diego, CA", Address = "12887 Scripps Summit Ct.", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image54.png", UriKind.RelativeOrAbsolute) }); list.Add(new Employee { Name = "Elizabeth Brow", Position = "Events Assistant", Team = "Sales", Office = "USA Office : Austin, TX", Address = "Brazos Street, Suite 400", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image56.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Deena Greece", Position = "Trainee", Team = "Sales", Office = "USA Office : Austin, TX", Address = "Brazos Street, Suite 400", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image57.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Janine Labrune", Position = "Events Assistant", Team = "Sales", Office = "Canada Office: Toronto", Address = "Toronto 110-556 Portage Ave. Winnipeg", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image58.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "John Steel", Position = "Events Assistant", Team = "Sales", Office = "Canada Office: Toronto", Address = "Toronto 110-556 Portage Ave. Winnipeg", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image59.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Jaime Yorres", Position = "Trainee", Team = "Sales", Office = "USA Office : Austin, TX", Address = "510 Brazos Street, Suite 400", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image60.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Aria Cruz", Position = "Trainee", Team = "Sales", Office = "San Diego, CA", Address = "12887 Scripps Summit Ct.", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image61.png", UriKind.RelativeOrAbsolute) }); list.Add(new Employee { Name = "Peter Franken", Position = "Trainee", Team = "Finance", Office = "USA Office : San Diego, CA", Address = "12887 Scripps Summit Ct.", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image62.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Simon Crowther", Position = "Trainee", Team = "Finance", Office = "United Kingdom Office: London", Address = "15 Bedford Square London WC81C 15JA", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image63.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "John Terry", Position = "Brand Manager", Team = "Finance", Office = "United Kingdom Office: London", Address = "15 Bedford Square London WC81C 15JA", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image64.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Michael Holz", Position = "Brand Manager", Team = "Finance", Office = "United Kingdom Office: London", Address = "110-556 Portage Ave. Winnipeg, R3B 5A7", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image65.png", UriKind.RelativeOrAbsolute) });
list.Add(new Employee { Name = "Georg Pipps", Position = "Brand Manager", Team = "Finance", Office = "Canada Office: Toronto", Address = "15 Bedford Square London WC81C 15JA", PhotoPath = new Uri("../../Images/ListBox/GroupingFiltering/Image66.png", UriKind.RelativeOrAbsolute) }); return list;
}
}
public class Employee
{
public string Name { get; set; }
public string Position { get; set; }
public string Team { get; set; }
public string Office { get; set; }
public string Address { get; set; }
public Uri PhotoPath { get; set; }
}
}
<ListBox ItemTemplate="{DynamicResource DataTemplate1}" ItemsSource="{Binding TheSource2.View}"/>
代码很详细,主要使用
e.Accepted true 或 false 来控制筛选
wpf,CollectionViewSource,使用数据过滤 筛选 功能。的更多相关文章
- wpf mvvm datagrid数据过滤
原文:wpf mvvm datagrid数据过滤 datagrid数据过滤,你可以通过设置RowStyle属性,通过将Visibility绑定到ViewModel层的属性来控制是否可见,比如: & ...
- snapde的批量文件数据过滤保存功能
一.snapde基本介绍 Snapde,一个专门为编辑超大型数据量CSV文件而设计的单机版电子表格软件:它运行的速度非常快,反应非常灵敏. 二.snapde批量数据筛选功能 如果想要对很多文件筛选出来 ...
- WPF gridcontrol 后台代码清除过滤筛选条件
WPF 后台清除gridcontrol过滤筛选条件: ColumnName:列名 user_GridControl:gridcontrol控件名 user_GridControl.ClearColum ...
- vue---数据列表过滤筛选
使用vue进行数据过滤筛选是比较常用的功能,常见的使用场景就是搜索框数据筛选过滤了.简单示例: <template> <div> <input type="te ...
- DataGridView如何实现列标头带数据筛选功能,就象Excel高级筛选功能一样
'近日有本论坛网友问:DataGridView如何实现列标头带数据筛选功能,就象Excel高级筛选功能一样 '今晚正好闲着没事,加之以前也没用到过这个需求,所以就写了个模拟功能,供各位坛友酌情参考. ...
- vue遍历数据是对数据进行筛选 过滤 排序
使用computed 方法来过滤筛选数据;或者使用methods 方式来筛选过滤数据 <body> <div id="app"> <ul> &l ...
- [WPF自定义控件库]排序、筛选以及高亮
1. 如何让列表的内容更容易查找 假设有这么一个列表(数据源在本地),由于内容太多,要查找到其中某个想要的数据会比较困难.要优化这个列表,无非就是排序.筛选和高亮. 改造过的结果如上. 2. 排序 在 ...
- C#实现通用数据过滤窗体
最近一直在做WINFORM项目,所以经常有些新的想法或尝试与大家分享,之前与大家分享了通用窗体遮罩层.通用可附加数据绑定的DataGridView.窗体渐显,今天来分享一个大家在其它软件中常见的功能: ...
- cxGrid控件过滤筛选后如何获更新筛选后的数据集
cxGrid控件过滤筛选后如何获更新筛选后的数据集 (2015-06-19 12:12:08) 转载▼ 标签: delphi cxgrid筛选数据集 cxgrid过滤 分类: Delphi cxGri ...
随机推荐
- xcode报错,svn : is not a workingCopy
解决方案: 1.点击对应的targets 2.选择build phases 3.在红框处有一个run script选项(截图中已经删除了.),点击下拉按钮,看看是否是与svn有关的东西, 如果是,删除 ...
- objective-c数组
1 #pragma mark -----------数组的初始化方式-------------- 2 // insert code here... 3 // NSLo ...
- August 31st 2016 Week 36th Tuesday
A friend without faults will never be found. 没有缺点的朋友是永远找不到的. You can't find a friends without faults ...
- poj1988(并查集)
题目链接:http://poj.org/problem?id=1988 题意:有n个箱子,初始时每个箱子单独为一列: 接下来有p行输入,M, x, y 或者 C, x: 对于M,x,y:表示将x箱子所 ...
- Swift - 多行文本输入框(UITextView)
1,多行文本控件的创建 1 2 3 4 let textview = UITextView(frame:CGRect(x:10, y:100, width:200, height:100)) text ...
- 命令行登陆Oracle(包括远程登陆)
本方法适用于在cmd命令行窗口以及pl/sql登陆Oracle下登录本机或者远程Oracle. 1.首先保证在当前主机上设置了ORACLE_HOME环境变量: 例如:ORACLE_HOME=D ...
- Java Hour 67 Java Collection API
本文不是一个大而全的讲述Java Coleection 相关的APi, 而是笔者认为哪些是一个初学者所能够而且必须确切知道的知识点. Collection 一脉 这里有我们比较常用的List<E ...
- 常见IE浏览器bug及其修复方案(双外边距、3像素偏移、绝对定位)
1. 双外边距浮动bug IE6和更低版本中存在双外边距浮动bug,顾名思义,这个Windows bug使任何浮动元素上的外边距加倍 bug重现: <!DOCTYPE html> < ...
- linux中socket的理解
对linux中socket的理解 一.socket 一般来说socket有一个别名也叫做套接字. socket起源于Unix,都可以用“打开open –> 读写write/read –> ...
- MySQL中的约束简单使用
数据库约束是为了保证数据的完整性而实现的一套机制,它具体的根据各个不同的数据库的实现而有不同的工具.一般来说有以下几种实现方式:1.检查约束:通过在定义数据库表里,在字段级或者是在表级加入的检查约束, ...