新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
WPF更新數據源相關操作指南
WPF數據源的操作對于一個初學者來說可能還不能很好的把握其要領。我們在這里就為大家介紹一下有關WPF更新數據源的相關介紹。#t#

為貢嘎等地區(qū)用戶提供了全套網頁設計制作服務,及貢嘎網站建設行業(yè)解決方案。主營業(yè)務為網站設計制作、網站建設、貢嘎網站設計,以傳統(tǒng)方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
WPF更新數據源1.讓對象實現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更新數據源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}"- />
這里又出現了新的綁定語法,{Binding Path=Age}等價{Binding Age}
WPF更新數據源3.目標:
當更改目標屬性的時候,更新數據源(更新以后則綁定的對象也發(fā)生變化,如更改TextBox的Text則Label的Content也發(fā)生變化)
WPF更新數據源4.設置更新數據源執(zhí)行時間
通過設置Binding對象的UpdateSourceTrigger 來確定執(zhí)行時間.
根據需要設置UpdateSourceTrigger 屬性
新聞名稱:WPF更新數據源相關操作指南
瀏覽地址:http://www.5511xx.com/article/dheoidp.html


咨詢
建站咨詢
