WPF更新数据源
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace Leo.WpfTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.InitData();
}
internal void InitData()
{
IList<ModCls> modsCls = new List<ModCls>();
for (int i = 0; i < 60; i++)
{
ModCls mod = new ModCls();
mod.A = "A" + i;
mod.B = "B" + i;
mod.C = "C" + i;
modsCls.Add(mod);
}
this.gridCls.ItemsSource = modsCls;
this.gridCls.RefreshData();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
ModCls mod = new ModCls();
mod.A = "A0";
mod.B = "BB";
mod.C = "CC";
IList<Leo.WpfTest.ModCls> temp = this.gridCls.ItemsSource as List<Leo.WpfTest.ModCls>;
IList<Leo.WpfTest.ModCls> tempA = (from p in temp
where p.A == mod.A
select p).ToList();
if (tempA != null && tempA.Count > 0)
{
for (int i = 0; i < temp.Count; i++)
{
if (temp[i].A == mod.A)
{
temp[i] = mod;
continue;
}
}
this.gridCls.RefreshData();
}
}
}
public class ModCls : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string a;
public string A
{
set
{
a = value;
if (PropertyChanged != null)//有改变
{
PropertyChanged(this, new PropertyChangedEventArgs("A"));
}
}
get
{
return a;
}
}
private string b;
public string B
{
set
{
b = value;
if (PropertyChanged != null)//有改变
{
PropertyChanged(this, new PropertyChangedEventArgs("B"));
}
}
get
{
return b;
}
}
private string c;
public string C
{
set
{
c = value;
if (PropertyChanged != null)//有改变
{
PropertyChanged(this, new PropertyChangedEventArgs("C"));
}
}
get
{
return c;
}
}
}
}
WPF更新数据源的更多相关文章
- WPF 自带Datagrid编辑后无法更新数据源的问题
原文 WPF 自带Datagrid编辑后无法更新数据源的问题 解决办法: 在列的绑定属性里加上UpdateSourceTrigger,示例XAML如下 <DataGrid Grid.Row=& ...
- WPF 针对数据源某个属性进行排序
原文:WPF 针对数据源某个属性进行排序 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wanlong360599336/article/detai ...
- 【C#】让DataGridView输入中实时更新数据源中的计算列
本文适用Winform开发,且DataGridView的数据源为DataTable/DataView的情况. 理解前提:熟知DataTable.DataView 求:更好方案 考虑这样一个场景: 某D ...
- WPF 将数据源绑定到TreeView控件出现界面卡死的情况
首先来谈一下实现将自定义的类TreeMode绑定到TreeView控件上的一个基本的思路,由于每一个节点都要包含很多自定义的一些属性信息,因此我们需要将该类TreeMode进行封装,TreeView的 ...
- WPF 的 数据源属性 和 数据源
(一)数据源(数据对象)属性 :path 或 path的值(path=VM.Property或M.Property),通常具有通知功能(特例除外). (二)path不能孤立而存在,它一定具有所归属的 ...
- WPF绑定数据源之RelativeSource
Command="{Binding ConfirmRegisterCommand}" CommandParameter="{Binding RelativeSource= ...
- Dev GridControl数据修改后实时更新数据源
1: /// <summary> 2: /// 嵌入的ComboxEdit控件选择值变化事件 3: /// </summary> 4: /// <param n ...
- WPF绑定数据源
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Comp ...
- Dev GridControl数据修改后实时更新数据源(转)
1: /// <summary> 2: /// 嵌入的ComboxEdit控件选择值变化事件 3: /// </summary> 4: /// <param nam ...
随机推荐
- asp.net MVC ViewData详解
转自:http://www.cnblogs.com/gaopin/archive/2012/11/13/2767515.html 控制器向视图中传值ViewData详解 1.将一个字符串传值到视图中 ...
- C语言qsort函数用法
qsort函数简介 排序方法有很多种:选择排序,冒泡排序,归并排序,快速排序等. 看名字都知道快速排序是目前公认的一种比较好的排序算法.因为他速度很快,所以系统也在库里实现这个算法,便于我们的使用. ...
- 【extjs】 extjs5 Ext.grid.Panel 搜索示例
先看效果图: 页面js: <script type="text/javascript"> /** * 日志类型 store * */ var logTypeStore ...
- [Hibernate] - Study test project
最近玩Hibernate的测试代码工程: http://files.cnblogs.com/HD/TestHibernate.7z
- Angular学习(8)- directive
<!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 9</ti ...
- 恢复ext4文件系统superblock
恢复ext4文件系统superblock 1. Create ext4 文件系统. [root@localhost ~]# mkfs.ext4 /dev/vdb1 [root@localhost ~] ...
- centos7开机/etc/rc.local不执行的问题
最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/etc/rc.local文件内容的就发现了问题的原因了 #!/bin/bash# THIS FILE IS ADDED ...
- 【gradle】之maven主库找不到Could not find org.restlet.jee:org.restlet:2.1.1
Could not find org.restlet.jee:org.restlet:2.1.1. 我是用gradle构建solr的时候出现的这个错误,通过google查询到这么一段解释 For th ...
- Return 和 Break 的区别
前段日子发布的负面情绪太多了,哦哦,其实我需要的是努力,努力提高自己的真实能力.经历了好多的鄙视否定,我已经没有最初那么敏感,心态平和了许多.我没有借口说基础不好了,一年了,要努力的话,那么我应该不会 ...
- 关于mac mini组装普液晶显示器
申请了好久的mac mini,部门终于给买下来了.没想到,买回来之后的组装还是折腾了我们一把. 因为先前没用过mac mini,以为它和普通的台式机一样,买回来就能直接到显示器上用了.结果买回来ma ...