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 ...
随机推荐
- Mysql源码分析--csv存储引擎
一直想分析下mysql的源码,开始的时候不知道从哪下手,先从csv的文件存储开始吧,这个还是比较简单的.我是用的是mysql5.7.16版本的源码. csv源码文件在mysql源码的mysql-5.7 ...
- shared_ptr 和 unique_ptr
c++11标准废除乐auto_ptr, C++ 标准库智能指针 使用这些智能指针作为将指针封装为纯旧 C++ 对象 (POCO) 的首选项. unique_ptr 只允许基础指针的一个所有者. 除非你 ...
- nyoj1007(euler 函数)
euler(x)公式能计算小于等于x的并且和x互质的数的个数: 我们再看一下如何求小于等于n的和n互质的数的和, 我们用sum(n)表示: 若gcd(x, a)=1,则有gcd(x, x-a)=1: ...
- myeclipse相关
:) MyEclipse 10.7以后开始支持JDK1.7,修改settings下面的配置文件没卵用.
- 三、jQuery--jQuery基础--jQuery基础课程--第6章 jQuery 事件与应用
1.页面加载时触发ready()事件 ready()事件类似于onLoad()事件,但前者只要页面的DOM结构加载后便触发,而后者必须在页面全部元素加载成功才触发,ready()可以写多个,按顺序执行 ...
- php的错误级别
error_reporting() 用于设置 PHP 的报错级别并返回当前级别.(PHP 4, PHP 5) 函数能够在运行时设置 error_reporting 指令. PHP 有诸多错误级别,使用 ...
- Linux下pipe使用注意事项
转自:http://blog.yufeng.info/archives/1485 Linux下的pipe使用非常广泛, shell本身就大量用pipe来粘合生产者和消费者的. 我们的服务器程序通常会用 ...
- Android中Service 使用详解(LocalService + RemoteService)
Service 简介: Service分为本地服务(LocalService)和远程服务(RemoteService): 1.本地服务依附在主进程上而不是独立的进程,这样在一定程度上节约了资源,另外L ...
- C 和 C++ 混合代码 cmath编译出错
最近在网上下载了 Triangle 库,准备在程序中调用来三角化生成网格,但出现了很多错误,如下: 1> triangle.c1>d:\program files\visualstudi ...
- Request和Response对象
Request 和 Response 对象起到了服务器与客户机之间的信息传递作用.Request 对象用于接收客户端浏览器提交的数据,而 Response 对象的功能则是将服务器端的数据发送到客户端浏 ...