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 ...
随机推荐
- NEFU 505 超级红与黑 (高斯消元)
题目链接 中文题,改下模板构造一下就能过了,数据有点水,不过还是需要自由变元枚举的. #include <iostream> #include <cstdio> #includ ...
- php图片防盗链的小测试
test.php <?php $txt = "http://hiphotos.baidu.com/stupidet/pic/item/4f1b8cfb4c33b7254e4aea69. ...
- 关于Windows下的文件后缀名问题
一.背景说明 有很多的小伙伴对windows下的文件后缀名不能很好地理解作用和区别,更不用说高深的使用了,在这里给大家说一下这些文件后缀名到底有什么区别,有什么作用呢? 二.说明 简单的说来,wind ...
- sql中union和union all的用法
如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并在一起显示出来. union和unio ...
- Linux系统入门学习:在curl中设置自定义的HTTP头
http://www.linuxidc.com/Linux/2015-02/114220.htm
- js 横幅播放
js 横幅播放 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- hdu 4046 2011北京赛区网络赛G 线段树 ***
还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #defi ...
- linux 读写锁应用实例
转自:http://blog.csdn.net/dsg333/article/details/22113489 /*使用读写锁实现四个线程读写一段程序的实例,共创建了四个新的线程,其中两个线程用来读取 ...
- C# 编码转换 UTF8转GB2312 GB2312转UTF8
/// <summary> /// GB2312转换成UTF8 /// </summary> /// <param name="text">&l ...
- 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...