码迷,mamicode.com
首页 > 其他好文 > 详细

WPF更新数据源

时间:2014-05-12 04:19:45      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:class   tar   ext   c   int   get   

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更新数据源,布布扣,bubuko.com

WPF更新数据源

标签:class   tar   ext   c   int   get   

原文地址:http://www.cnblogs.com/binbinxiong/p/3721245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!