Created
April 18, 2013 14:59
-
-
Save ericsk/5413407 to your computer and use it in GitHub Desktop.
使用 ObservableCollection 容器取代 List 容器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| 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