日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

win8和win8.1动态绑定数据到ListView

發布時間:2025/6/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 win8和win8.1动态绑定数据到ListView 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public string stuName { get; set; }public int stuAge { get; set; }} 然后就是new一個Student對象,往里面添加值了,這邊又有兩種方法:

一種是類似java的方法(不知道java是不是有更簡便的方法,這種方法個人感覺有點麻煩):

Student stu = new Student { stuName = "鋼鐵俠", stuAge = 40 }; Student stu1 = new Student { stuName = "蜘蛛俠", stuAge = 40 }; Student stu2 = new Student { stuName = "蝙蝠俠", stuAge = 40 }; Student stu3 = new Student { stuName = "綠巨人", stuAge = 40 }; Student stu4 = new Student { stuName = "黑寡婦", stuAge = 40 }; Student stu5 = new Student { stuName = "美國隊長", stuAge = 40 }; List<Student> stuList = new List<Student>();//泛型,這個也是java中的寫法 stuList.Add(stu); stuList.Add(stu1); stuList.Add(stu2); stuList.Add(stu3); stuList.Add(stu4); stuList.Add(stu5); 還有一個是C#的寫法: List<Student> stuList = new List<Student> { new Student{ stuName = "鋼鐵俠", stuAge = 40 }, new Student{ stuName = "蜘蛛俠", stuAge = 40 }, new Student{ stuName = "蝙蝠俠", stuAge = 40 }, new Student{ stuName = "黑寡婦", stuAge = 40 }, new Student{ stuName = "綠巨人", stuAge = 40 } }; 以上的不同寫法都完成了一個目的,就是給stuList賦值了。這也 解決了第二個問題,數據從哪里來的問題。

最后我們就是要完成綁定的步驟了。這個只需要一行代碼就能把數據送到前臺的ListView讓其顯示。 這樣就完成了最后一個問題,怎樣綁定的問題。

注意:這里的 listBind 就是前臺的ListView的唯一指定。

listBind.ItemsSource = stuList;

運行程序,就能看到ListView里面有值了,如下圖所示:

總結

以上是生活随笔為你收集整理的win8和win8.1动态绑定数据到ListView的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。