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 ...
随机推荐
- 推荐一个大文件查找工具---WizTree
DB备份.dump.电影等文件多了以后,经常遇到磁盘空间不够用的情况,日积月累本来清晰的目录结构找起来也很费劲,尤其是要查找删除无用的大文件.windows本身那差劲的搜索功能就不提了,从搜索引擎上查 ...
- [转]StringUtils方法
摘自http://blog.sina.com.cn/s/blog_4550f3ca0100qrsd.html org.apache.commons.lang.StringUtils中方法的操作对象是j ...
- Struts2 - Check Login Interceptor
Struts2使用Interceptor做用户登陆检查: 1)新增一个bean: User.java package com.my.beans; import java.util.Date; impo ...
- Struts2 - Rest(1)
Struts2提供了一个restful的插件:struts2-rest-plugin-2.3.16.1.jar 这个插件可以把Struts2当做restful来使用,不过它的rest功能目前来说有点“ ...
- 在WINDOWS SERVER 上或远程桌面中使用 MUTEX
引用: http://www.cnblogs.com/fg0711/archive/2012/05/03/2480502.html 使用Mutex需要注意的两个细节 可能你已经注意到了,例子中在给Mu ...
- 读书笔记:应用随机过程:概率模型导论:Aloha协议问题
例4.16,Aloha协议:就本书例题所涉及的部分来说,几乎等同于CSMA.这个例题重写如下: 考察一个包含多个设备的通信系统,其中在每个时间段发送信息的设备个数是独立同分布的.......每个设备将 ...
- 51nod 1411 矩阵取数问题 V3
给定一个m行n列的矩阵,你可以从任意位置开始取数,到达任意位置都可以结束,每次可以走到的数是当前这个数上下左右的邻居之一,唯一的限制是每个位置只能经过一次,也就是说你的路径不自交.所经过的数的总作为你 ...
- Force IE to Open Link in New Tab
1.First, open Internet Explorer and click on Tools and then Internet Options. 2.Now click on the Set ...
- 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- ios8 ios7 tableview cell 分割线左对齐
ios8中左对齐代码 //加入如下代码 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cel ...