Skip to content

Instantly share code, notes, and snippets.

@ericsk
Created April 18, 2013 14:59
Show Gist options
  • Select an option

  • Save ericsk/5413407 to your computer and use it in GitHub Desktop.

Select an option

Save ericsk/5413407 to your computer and use it in GitHub Desktop.
使用 ObservableCollection 容器取代 List 容器
...
using System.Collections.ObjectModel;
...
// 建立容器,裝訊息資料
ObservableCollection<MessageModel> myList = new ObservableCollection<MessageModel>();
// 將容器連結至 <ListView />
MyListView.ItemsSource = myList;
// 把資料裝入容器內,<ListView /> 控制項也會逐一顯示
...
private void OnButtonClicked(object sender, RoutedEventArgs e)
{
// 拿出 ListView 中的 ItemsSource
ObservableCollection<MessageModel> items = (ObservableCollection<MessageModel>)MyListView.ItemsSource;
// 修改其中一筆資料的內容
items[0].Name = "Dan";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment