public ObservableCollection<CustomerModel> CustomerCollection
{
get
{
if(customerCollection!=null)
{
var thirdList = customerCollection.ToList().OrderBy(x => x.RowGuid).ToList();
customerCollection.Clear();
foreach(var cus in thirdList)
{
customerCollection.Add(cus);
}
}
return customerCollection;
}
set
{
customerCollection = value;
OnPropertyChanged("CustomerCollection");
}
}

private ICommand loadCmd;
public ICommand LoadCmd
{
get
{
if(loadCmd==null)
{
loadCmd = new DelegateCommand<string>((obj) =>
{
FillDG();
});
}
return loadCmd;
}
}

private void FillDG()
{
List<CustomerModel> customerList = new List<CustomerModel>();
string source = ConfigurationSettings.AppSettings["SqlSource"];
SqlConnection conn = new SqlConnection(source);
conn.Open();
if(conn.State==ConnectionState.Open)
{
string sql = " select name,ProductNumber,rowguid from Production.Product";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
customerList.Add(new CustomerModel()
{
Name = ds.Tables[0].Rows[i][0].ToString(),
ProductName = ds.Tables[0].Rows[i][1].ToString(),
RowGuid = ds.Tables[0].Rows[i][2].ToString()
});
}
}
}

CustomerCollection = new ObservableCollection<CustomerModel>(customerList);
}

WPF ItemsSource Order by Getter的更多相关文章

  1. 菜单根据菜单ID向下递归

    第一步:我们根据这个类定义数据库,并插入菜单数据 DROP TABLE IF EXISTS `jrbac_menu`; CREATE TABLE `jrbac_menu` ( `id` ) NOT N ...

  2. 【转】Hibernate 原汁原味的四种抓取策略

    最近在研究 Hibernate 的性能优化的时候碰到了"抓取策略", 由于以前没有详细的研究过, 所以到处找资料, 但是无论从一些讲 Hibernate 书籍,还是他人 Blog ...

  3. Hibernate 原汁原味的四种抓取策略(转)

    原文出处:http://www.cnblogs.com/rongxh7/archive/2010/05/12/1733088.html     尊重原作者,访问原创地址 最近在研究 Hibernate ...

  4. MyBatis框架之第二篇

    1.高级参数映射和返回值映射(重点) a)Pojo包装pojo的参数映射 b)当结果集列名与pojo属性名不一致的返回值映射 2.动态sql(重点) 3.关联查询结果(重点) a)一对一关联结果 b) ...

  5. Mybatis(下)

    Mybatis(下) 一.MaBatis核心配置文件 Mybatis 中文文档 Mybatis 中文文档 1. properties 定义属性及读取属性文件,取的时候用 $(name) ,name 为 ...

  6. WPF的DataGrid绑定ItemsSource后第一次加载数据有个别列移位的解决办法

    最近用WPF的DataGrid的时候,发现一个很弱智的问题,DataGrid的ItemsSource是绑定了一个属性: 然后取数给这个集合赋值的时候,第一次赋值,就会出现列移位 起初还以为是显卡的问题 ...

  7. WPF中 ItemsSource 和DataContext不同点

    此段为原文翻译而来,原文地址 WPF 中 数据绑定 ItemSource和 DataContext的不同点: 1.DataContext 一般是一个非集合性质的对象,而ItemSource 更期望数据 ...

  8. Enum Binding ItemsSource In WPF

    Enum Binding ItemsSource In WPF   在WPF中枚举绑定到ItemsSource. 一.通过ObjectDataProvider 获取Enum数据源 首先我们定义一个En ...

  9. WPF学习笔记——ListBox用ItemsSource绑定数据源

    作为一个WPF初学者,感到困难重重.在网上想查个ListBox绑定数据源的示例,结果出来一大堆代码,一看心就烦. 我给个简洁一点的代码: 后台代码: protected class UserItem ...

随机推荐

  1. PHP面试题2019年滴滴出行工程师面试题及答案解析

    一.单选题(共30题,每题5分) 1.下列关于PHP垃圾回收的说法,错误的是? A.开启/关闭垃圾回收机制可以通过修改php配置实现 B.可以在程序中使用gc_enable() 和 gc_disabl ...

  2. elasticsearch window下配置安装

    1.首先下载elasticsearch 下载链接:https://www.elastic.co/cn/downloads/elasticsearch 第一张图是下载的,第二章图是下载msi的程序,直接 ...

  3. 权限管理——ACL权限

    权限管理 ACL权限 用于解决用户对文件身份不足 命令:[root@localhost ~]#dumpe2fs -h /dev/sd3 作用:查询指定分区详细的文件系统给信息 选项 -h:仅显示超级块 ...

  4. 文:你可以杀我,但你不能评价(judge)我

    原创 豆瓣影评:“现代战争启示录”豆友影评 2006-12-18 20:24:20 本文刊载于<豆瓣影评>豆友“芹泽虾饺菌”的影评  原文标题<剃刀边缘的疯狂> 文/芹泽虾饺菌 ...

  5. [PHP] 配置vscode的语法检测消除提示Cannot validate since no PHP executable is set

    默认下载完vscode什么都不做,会提示一下信息Cannot validate since no PHP executable is set. Use the setting 'php.validat ...

  6. Java面试题-基础篇二(干货)

    11.是否可以从一个static方法内部发出对非static方法的调用? 不可以.因为非static方法是要与对象关联在一起的,必须创建一个对象后,才可以在该对象上进行方法调用,而static方法调用 ...

  7. SpringBoot2.x项目pom.xml第一行报错

    原来使用的是2.1.4 后来改成2.1.3 保存自动从新下载就好了    毕竟使用人数多 maven地址:https://mvnrepository.com/artifact/org.springfr ...

  8. 12Java基础_数组定义格式/动态初始化/静态初始化

    /* Java数组 格式一: int[] array; 格式二: int array[]; 数组初始化: 为数组中的元素分配内存空间 动态初始化: int[] array=new int[数组长度] ...

  9. [C4W4] Convolutional Neural Networks - Special applications: Face recognition & Neural style transfer

    第四周:Special applications: Face recognition & Neural style transfer 什么是人脸识别?(What is face recogni ...

  10. [C2] 逻辑回归(Logistic Regression)

    逻辑回归(Logistic Regression) 假设函数(Hypothesis Function) \(h_\theta(x)=g(\theta^Tx)=g(z)=\frac{1}{1+e^{-z ...