zoukankan
html css js c++ java
wpf学习笔记更新数据源
此示例基于
wpf学习笔记-指定数据源
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));
}
}
}
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 属性
完
查看全文
相关阅读:
poj2392 Space Elevator(多重背包问题)
poj1703 Find them, Catch them(并查集的应用)
HDU 1867 A + B for you again(KMP算法的应用)
HDU 1358 Period(kmp简单解决)
nyoj 460 项链 (区间dp)
Python内置函数(9)——callable--转载
Python的hasattr() getattr() setattr() 函数使用方法详解--转载
python assert 断言详细用法格式
sam文件格式
Linux中重定向--转载
原文地址:https://www.cnblogs.com/Clingingboy/p/1211173.html
最新文章
docker 不同机器上容器互相通信
ruby gem tips(转)
mysql操作及自动化运维
mysql 安装
ruby,python及curl post请求
如何创建自己的ruby gem包
ubuntu 设置虚拟机和主机在同一网段
Ubuntu下libpcap安装步骤
C++ 输出精度和输出小数点位数
Win10 DHCP和Static IP 切换
热门文章
修改QPushButton北京颜色和字体背景
QWidget::setLayout: Attempting to set QLayout "" on MainWindow "", which already has a layout
PCL 平面模型分割
boost库中sleep方法详解
QT编译时出现警告 Warning: Class Node implements the interface QGraphicsItem but does not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!
一个简单题,引发的思索 + nyoj 1189
hdu Distant Galaxy(遥远的银河)
蓝桥杯第五届B组 李白打酒
天猫 小游戏 24 point
2014年亚洲赛区西安站赛后反思
Copyright © 2011-2022 走看看