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 属性
完
查看全文
相关阅读:
安卓开发学习——事件机制
安卓开发学习——消息机制与异步任务
安卓存储学习
scrollTop, pageYOffset, scrollY 以及offsetTop 的区别
BFC与IFC概念理解+布局规则+形成方法+用处
JavaScript的作用域、作用域链和执行期上下文
深入理解javascript原型和闭包系列
【剑指Offer】剑指offer题目汇总
CSS文件加载方式: @import 和 <link>
jquery跨域:$.ajax 和$.getJSON
原文地址:https://www.cnblogs.com/Clingingboy/p/1211173.html
最新文章
关于子页面调用父页面的方法
让bootstrap的垂直菜单默认打开
bootstrap模态框使用
web标准、可用性、可访问性
关于ev||event事件对象的兼容写法
草根程序员如何进入BAT
关于js对象中的,属性的增删改查问题
JQ中的问题
浅析document和window的区别
正则表达式的() [] {}有不同的意思。
热门文章
关于菜鸟程序员如何成长
浅析 var that = this;
设置断点
WPF学习2
WPF学习1
安卓开发学习——图像处理
安卓开发学习——Fragment
安卓开发学习——广播接收器
安卓开发学习——四大组件之Service
安卓开发学习——自定义控件
Copyright © 2011-2022 走看看