We will be using a CollectionView to display the messages in the chat app. Again, perform the following steps and take a look at the code to make sure you understand each step:
- Locate the <!-- TODO Add CollectionView --> comment in the ChatView.xaml file.
- Add a CollectionView and set the x:Name property to MessageList.
- Data-bind CollectionView by setting the ItemsSource property to {Binding Messages}. This will make CollectionView aware of any changes that are made in ObservableCollection<Message>, which is exposed through the Messages property. Any time a message is added or removed, ListView will update to reflect this change.
- Add the SelectMessageTemplate resource we defined in the previous section to the ItemTemplate property. This will run some code each time an item is added to make sure that we programmatically select the correct visual template for a specific message. Don't worry about this right now...