這篇文章主要介紹了C#中WPF ListView綁定數(shù)據的示例分析,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)是專業(yè)的垣曲網站建設公司,垣曲接單;提供網站制作、網站設計,網頁設計,網站設計,建網站,PHP網站建設等專業(yè)做網站服務;采用PHP框架,可快速的進行垣曲網站開發(fā)網頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網站,專業(yè)的做網站團隊,希望更多企業(yè)前來合作!C#中WPF ListView綁定數(shù)據的實例詳解
WPF中ListView用來顯示數(shù)據十分方便, 我們可以將它分成幾個列,每一個列用來顯示一條數(shù)據,但是又是在一方之中。
那么怎樣實現(xiàn)這樣的效果的呢,這就要用綁定了。
我們先來看一看他的xmal代碼
<ListView Name="receiveList" Grid.Row="0"> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header="發(fā)件人" Width="200" DisplayMemberBinding="{Binding Path=Senderuser}" /> <GridViewColumn Header="主題" Width="350" DisplayMemberBinding="{Binding Path=Topic}" /> <GridViewColumn Header="附件" DisplayMemberBinding="{Binding Path=Ffile}" Width="200" /> <GridViewColumn Header="時間" Width="150" DisplayMemberBinding="{Binding Path=Time}"/> </GridView.Columns> </GridView> </ListView.View> </ListView>
上面的代碼中每一個GridViewColumn都有一個綁定{Bind Path=作為綁定源的類中的成員屬性}
下面來看一下綁定的類
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EmailClient { class MailList : INotifyPropertyChanged { public string senduser; public string topic; public string file; public string time; public event PropertyChangedEventHandler PropertyChanged; public string Senderuser { get { return senduser; } set { senduser = value; if (this.PropertyChanged != null)//激發(fā)事件,參數(shù)為Age屬性 { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age")); } } } public string Topic { get { return topic; } set { topic = value; if (this.PropertyChanged != null)//激發(fā)事件,參數(shù)為Age屬性 { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age")); } } } public string Ffile { get { return file; } set { file = value; if (this.PropertyChanged != null)//激發(fā)事件,參數(shù)為Age屬性 { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age")); } } } public string Time { get { return time; } set { time = value; if (this.PropertyChanged != null)//激發(fā)事件,參數(shù)為Age屬性 { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age")); } } } public MailList() { } public MailList(string senduser,string topic,string file,string time) { this.senduser = senduser; this.topic = topic; this.file = file; this.time = time; } } }
現(xiàn)在我們可以看到我們剛才綁定的屬性就在這個類中,那么該怎樣應用呢
下面來看一下我的應用代碼
private List<MailList> maillist;
maillist = new List<MailList>();
以上的代碼是聲明一個list來保存我們插入的數(shù)據的,由于我的源代碼是從服務器中得到的郵件列表。
maillist.Add(new MailList("xxxxxx", "xxxxxxxx", "xxxxxx", "xxxxxx"));
receiveList.ItemsSource = maillist;
如果這樣寫那么那么上面的途中得到的就是xxxxxx了。
那么綁定就是這樣了。
感謝你能夠認真閱讀完這篇文章,希望小編分享的“C#中WPF ListView綁定數(shù)據的示例分析”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián)成都網站建設公司,關注創(chuàng)新互聯(lián)成都網站建設公司行業(yè)資訊頻道,更多相關知識等著你來學習!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、網站建設公司香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
當前題目:C#中WPFListView綁定數(shù)據的示例分析-創(chuàng)新互聯(lián)
網站網址:http://aaarwkj.com/article30/ccosso.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供微信小程序、動態(tài)網站、響應式網站、搜索引擎優(yōu)化、用戶體驗、網站改版
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)