新聞中心
WPF數(shù)據(jù)源的操作對(duì)于一個(gè)初學(xué)者來(lái)說(shuō)可能還不能很好的把握其要領(lǐng)。我們?cè)谶@里就為大家介紹一下有關(guān)WPF更新數(shù)據(jù)源的相關(guān)介紹。#t#

為貢嘎等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及貢嘎網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè)、貢嘎網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
WPF更新數(shù)據(jù)源1.讓對(duì)象實(shí)現(xiàn)INotifyPropertyChanged接口,以便屬性更改發(fā)出通知
- 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 PropertyChanged
EventHandler PropertyChanged; - protected void OnProperty
Changed(string propName) - {
- if (this.PropertyChanged != null)
- {
- PropertyChanged(this, new
PropertyChangedEventArgs(propName)); - }
- }
- }
WPF更新數(shù)據(jù)源2.xaml(略去布局)
- < Label Content=
"{Binding Name}">< /Label>- < Label Content=
"{Binding Age}">< /Label>- < TextBox Text="{Binding
Path=Name, Source={Static
Resource Tom}}" />- < TextBox Text="
{Binding Age}"- />
這里又出現(xiàn)了新的綁定語(yǔ)法,{Binding Path=Age}等價(jià){Binding Age}
WPF更新數(shù)據(jù)源3.目標(biāo):
當(dāng)更改目標(biāo)屬性的時(shí)候,更新數(shù)據(jù)源(更新以后則綁定的對(duì)象也發(fā)生變化,如更改TextBox的Text則Label的Content也發(fā)生變化)
WPF更新數(shù)據(jù)源4.設(shè)置更新數(shù)據(jù)源執(zhí)行時(shí)間
通過(guò)設(shè)置Binding對(duì)象的UpdateSourceTrigger 來(lái)確定執(zhí)行時(shí)間.
根據(jù)需要設(shè)置UpdateSourceTrigger 屬性
分享文章:WPF更新數(shù)據(jù)源相關(guān)操作指南
分享URL:http://www.5511xx.com/article/dheoidp.html


咨詢
建站咨詢
