wpf学习笔记-更新数据源
来源:互联网 发布:如何进行淘宝店铺装修 编辑:程序博客网 时间:2024/06/11 20:14
此示例基于 wpf学习笔记-指定数据源
1.让对象实现INotifyPropertyChanged接口,以便属性更改发出通知
2.xaml(略去布局)
<Label Content="{Binding Name}"></Label>
<Label Content="{Binding Age}"></Label>
<TextBox Text="{Binding Path=Name, Source={StaticResource Tom}}" />
<TextBox Text="{Binding Age}"
/>这里又出现了新的绑定语法,{Binding Path=Age}等价{Binding Age}
3.目标:
当更改目标属性的时候,更新数据源(更新以后则绑定的对象也发生变化,如更改TextBox的Text则Label的Content也发生变化)
4.设置更新数据源执行时间
通过设置Binding对象的UpdateSourceTrigger 来确定执行时间.
根据需要设置UpdateSourceTrigger 属性
完
1.让对象实现INotifyPropertyChanged接口,以便属性更改发出通知
public class Person : INotifyPropertyChanged
{
public Person() { }
public Person(string name, int age)
{
this.name = name;
this.age = age;
}
string name;
public string Name
{
get { return this.name; }
set
{
this.name = value;
OnPropertyChanged("Name");
}
}
int age;
public int Age
{
get { return this.age; }
set
{
this.age = value;
OnPropertyChanged("Age");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
}
{
public Person() { }
public Person(string name, int age)
{
this.name = name;
this.age = age;
}
string name;
public string Name
{
get { return this.name; }
set
{
this.name = value;
OnPropertyChanged("Name");
}
}
int age;
public int Age
{
get { return this.age; }
set
{
this.age = value;
OnPropertyChanged("Age");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
}
2.xaml(略去布局)
<Label Content="{Binding Name}"></Label>
<Label Content="{Binding Age}"></Label>
<TextBox Text="{Binding Path=Name, Source={StaticResource Tom}}" />
<TextBox Text="{Binding Age}"
/>
3.目标:
当更改目标属性的时候,更新数据源(更新以后则绑定的对象也发生变化,如更改TextBox的Text则Label的Content也发生变化)
4.设置更新数据源执行时间
通过设置Binding对象的UpdateSourceTrigger 来确定执行时间.
根据需要设置UpdateSourceTrigger 属性
完
- wpf学习笔记-更新数据源
- wpf学习笔记-指定数据源
- WPF学习笔记——ListBox用ItemsSource绑定数据源
- WPF学习笔记——ListBox用ItemsSource绑定数据源
- Tomcat 数据源学习笔记
- 数据源(DataSource)学习笔记
- WPF使用DataGrid控件显示和更新ADO.NET数据源
- wpf学习笔记
- WPF学习笔记1
- WPF学习笔记一
- WPF学习笔记二
- WPF学习笔记--基本知识
- WPF学习笔记
- wpf学习笔记---TextBox
- wpf学习笔记---Button
- wpf学习笔记---Viewbox
- wpf学习笔记---Canvas
- wpf学习笔记---StackPanel
- wpf-Resource注意点
- wpf-DrawingBrush注意点
- wpf-容易误解的Image
- wpf轻量绘图DrawingVisual
- wpf学习笔记-数据绑定功能总结
- wpf学习笔记-更新数据源
- wpf学习笔记-指定数据源
- wpf学习笔记-简单绑定
- 自定义控件集
- 你使用控件吗?会用吗?
- jQuery事件总结
- vs2008中文版提供下载(包含中文msdn)
- asp.net控件开发基础示例代码打包
- 2007最后一贴