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 属性
完
查看全文
相关阅读:
25、DataReaderWriter
javascript 事件(基础)0831
html 表单下拉列表框
css
getElementById的三个用法
javascript原型对象prototype
JS String类型
javascript闭包及作用域
JavaScript匿名函数
Javascript表单(text,radio,checkbox等)验证大全0830
原文地址:https://www.cnblogs.com/Clingingboy/p/1211173.html
最新文章
第一个程序
初识exe程序[反汇编]小感(PEiD+DEDE)
浅谈共享软件如何被破解
图说浏览器历史
Eclipse中自动添加注释(作者,时间)
[自我学习用]Decompie破解一些软件的实例
[ZZ]愚人?Oracle挥舞法律大棒 JavaEye被逼改名ItEye
[C#反编译]Reflector相关及破解下载
[转载]谈软件的破解与保护
chrome五十大实用插件集合!
热门文章
Windows Live Writer的几种代码插件比较
31、StorageDataSource and GetVirtualizedFilesVector sample
27、FilePicker
33、ShareSource
29、WebSocket
28、FileThumbnails
Windows 8 Store 开发
32、ThreadPool
26、FileAccess
30、Stream socket
Copyright © 2011-2022 走看看