Now that the XAML is complete, we have some work to do in the code behind. We'll start by adding some using statements:
- Open the ChatView.xaml.cs file.
- Add using statements for Chat.ViewModels, Xamarin.Forms, and Xamarin.Forms.PlatformConfiguration.iOSSpecific.
- Add a private field called viewModel of the ChatViewModel type, which will hold a local reference to ChatViewModel.
The class should now look as follows. The code in bold indicates what should have changed:
using System.Linq;
using Chat.ViewModels;
using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
namespace Chat.Views
{
public partial class ChatView : ContentPage
{
private ChatViewModel viewModel;
public ChatView()
{
InitializeComponent();
}
}
}
When a new message arrives, this will be added to the Messages collection in ChatViewModel. To make sure that CollectionView scrolls appropriately so...