C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解
C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解
WPF中ListView用來(lái)顯示數(shù)據(jù)十分方便, 我們可以將它分成幾個(gè)列,每一個(gè)列用來(lái)顯示一條數(shù)據(jù),但是又是在一方之中。
那么怎樣實(shí)現(xiàn)這樣的效果的呢,這就要用綁定了。
我們先來(lái)看一看他的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="時(shí)間" Width="150" DisplayMemberBinding="{Binding Path=Time}"/> </GridView.Columns> </GridView> </ListView.View> </ListView>
上面的代碼中每一個(gè)GridViewColumn都有一個(gè)綁定{Bind Path=作為綁定源的類中的成員屬性}
下面來(lái)看一下綁定的類
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)在我們可以看到我們剛才綁定的屬性就在這個(gè)類中,那么該怎樣應(yīng)用呢
下面來(lái)看一下我的應(yīng)用代碼
private List<MailList> maillist;
maillist = new List<MailList>();
以上的代碼是聲明一個(gè)list來(lái)保存我們插入的數(shù)據(jù)的,由于我的源代碼是從服務(wù)器中得到的郵件列表。
maillist.Add(new MailList("xxxxxx", "xxxxxxxx", "xxxxxx", "xxxxxx"));
receiveList.ItemsSource = maillist;
如果這樣寫(xiě)那么那么上面的途中得到的就是xxxxxx了。
那么綁定就是這樣了。
如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
上一篇:C#中Socket與Unity相結(jié)合示例代碼
欄 目:C#教程
下一篇:C#中可枚舉類型詳解
本文標(biāo)題:C#中WPF ListView綁定數(shù)據(jù)的實(shí)例詳解
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5451.html
您可能感興趣的文章
- 01-10C#通過(guò)反射獲取當(dāng)前工程中所有窗體并打開(kāi)的方法
- 01-10C#實(shí)現(xiàn)Winform中打開(kāi)網(wǎng)頁(yè)頁(yè)面的方法
- 01-10C#實(shí)現(xiàn)由四周向中心縮小的窗體退出特效
- 01-10Extjs4如何處理后臺(tái)json數(shù)據(jù)中日期和時(shí)間
- 01-10C#中DataGridView常用操作實(shí)例小結(jié)
- 01-10C#編程獲取資源文件中圖片的方法
- 01-10asp.net中XML如何做增刪改查操作
- 01-10C#利用反射技術(shù)實(shí)現(xiàn)去掉按鈕選中時(shí)的邊框效果
- 01-10C#中查找Dictionary中的重復(fù)值的方法
- 01-10C#及WPF獲取本機(jī)所有字體和顏色的方法


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10C#通過(guò)反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁(yè)無(wú)法打開(kāi)的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過(guò)重寫(xiě)Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-10delphi制作wav文件的方法
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10C#中split用法實(shí)例總結(jié)
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什