title: Observable collection binding to list view won't show
body: <p>I am having trouble with my <code>View</code>, which won't bind my Observable Collection of type <code>UserModel</code>. The Data is being displayed with <code>Debug.WriteLine</code> it just won't bind to the <code>View</code>. Here is my code.</p>
  
  <p>View - Binding set by <code>ItemsSource</code>.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
           x:Class="Monger.View.HomePage"&gt;
  &lt;ContentPage.Content&gt;
      &lt;StackLayout  Orientation="Vertical"&gt;
          &lt;StackLayout Orientation="Horizontal" Padding="25,0,15,10" Margin="0,10,0,0"&gt;
                  &lt;StackLayout Orientation="Horizontal" Padding="10,0,5,0"&gt;
                      &lt;ic:CircleImage HeightRequest="60" WidthRequest="60" Aspect="AspectFill" Source="http://placekitten.com/400/300" HorizontalOptions="Start"/&gt;
                      &lt;Label Margin="9,0,0,0" VerticalOptions="CenterAndExpand" HorizontalOptions="EndAndExpand" FontSize="30" TextColor="#A3D1F5" Text="{Binding DeviceEui}"/&gt;
                  &lt;/StackLayout&gt;
              &lt;/StackLayout&gt;
              &lt;BoxView HeightRequest="1" BackgroundColor="Black" HorizontalOptions="FillAndExpand" /&gt;
          &lt;StackLayout Padding="20,0,20,0" Margin="0,10,0,0"&gt;
              &lt;ListView x:Name="DeviceListView" SelectedItem="{Binding DeviceSelected}" ItemSelected="DeviceList_ItemSelected" ItemsSource="{Binding DevicesDisplay}"  Header="Devices" SeparatorColor="#A3D1F5"&gt;
                  &lt;ListView.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;TextCell Text="{Binding DeviceEui}"/&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
              &lt;/ListView&gt;
          &lt;/StackLayout&gt;
          &lt;StackLayout Margin="0,0,0,30" Padding="20,0,20,0"&gt;
              &lt;Button Text="Add Device" BorderRadius = "20" BackgroundColor="#A3D1F5" Command="{Binding AddDeviceCommand}"/&gt;
          &lt;/StackLayout&gt;
      &lt;/StackLayout&gt;
  &lt;/ContentPage.Content&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>View Code Behind - Will slowly get rid of most of the code here to adhear to MVVM. At the moment it just checks permissions and if okay triggers <code>LoadDevicesCommand</code>, sets binding context to <code>HomePageViewModel</code> and initializes new <code>HomePageViewModel</code>.</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace Monger.View
  {
      [XamlCompilation(XamlCompilationOptions.Compile)]
      public partial class HomePage : ContentPage
      {
          public HomePage()
          {
              InitializeComponent();
              ViewModel = new HomePageViewModel(new PageService());
          }
  
          protected async override void OnAppearing()
          {
              try
              {
                  var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
                  if (status != PermissionStatus.Granted)
                  {
                      if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                      {
                          await DisplayAlert("Need location",
                              "We need your location to display where you are on the map.", "OK");
                      }
  
                      var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
                      //Best practice to always check that the key exists
                      if (results.ContainsKey(Permission.Location))
                          status = results[Permission.Location];
                  }
  
                  if (status == PermissionStatus.Granted)
                  {
                      ViewModel.LoadDevicesCommand.Execute(this);
                      base.OnAppearing();
                  }
                  else if (status != PermissionStatus.Unknown)
                  {
                      await DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
                  }
              }
              catch (Exception)
              {
              }
          }
  
          private HomePageViewModel ViewModel
          {
              get { return BindingContext as HomePageViewModel; }
              set { BindingContext = value; }
          }
  
          private void DeviceList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
          {
              ViewModel.DeviceSelectedCommand.Execute(e.SelectedItem);
          }
      }
  }
  </code></pre>
  
  <p>View Model - First time using Sqlite, creating a table and then grabbing the table on launch if it doesn't already exist. Setting up context actions for the future but can't get the bindings to work. Add Device adds a <code>UserModel</code> object, inserts it into the sql data base and then adds it to the Observable Collection of type <code>UserModel</code>. On Property Changed should have been triggered to update the bindings.</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace Monger.ViewModel
  {
      class HomePageViewModel : BaseViewModel
      {
          private HttpClient _client = new HttpClient();
          private ObservableCollection&lt;UserModel&gt; _devices;
          private readonly IPageService _pageService;
          private UserModel _deviceSelected;
  
          public UserModel DeviceSelected
          {
              get { return _deviceSelected; }
              set { SetValue(ref _deviceSelected, value); }
          }
  
          private List&lt;UserModel&gt; _userDevices;
          private SQLiteAsyncConnection _connection;
  
          public ObservableCollection&lt;UserModel&gt; DevicesDisplay
          {
              get { return _devices; }
              set { SetValue(ref _devices, value); }
          }
  
          public String _deviceEui;
  
          public ICommand DeviceSelectedCommand { get; private set; }
          public ICommand AddDeviceCommand { get; private set; }
          public ICommand LoadDevicesCommand { get; private set; }
  
          public HomePageViewModel(IPageService pageService)
          {
              _connection = DependencyService.Get&lt;ISQLiteDb&gt;().GetConnection();
              _pageService = pageService;
              LoadDevicesCommand = new Command(GetSqlConnection);
              AddDeviceCommand = new Command(AddDevice);
              DeviceSelectedCommand = new Command&lt;UserModel&gt;(async vm =&gt; await OnDeviceSelected(vm));
          }
  
          private async void GetSqlConnection()
          {
              await _connection.CreateTableAsync&lt;UserModel&gt;();
              _userDevices = await _connection.Table&lt;UserModel&gt;().ToListAsync();
              DevicesDisplay = new ObservableCollection&lt;UserModel&gt;(_userDevices);
          }
  
  
          private async Task OnDeviceSelected(UserModel Selected)
          {
              if (Selected == null)
                  return;
              DeviceSelected = null;
  
              _deviceEui = Selected.DeviceEui;
  
              await _pageService.PushModalAsync(new MapPage(_deviceEui));
          }
  
          public async void AddDevice()
          {
              var userdevice = new UserModel
                  { DeviceEui = "0000000000000777", DeviceName = "Ryans Laptop", DeviceCategory = "phone.png" };
              await _connection.InsertAsync(userdevice);
              DevicesDisplay.Add(userdevice);
              Debug.WriteLine(_devices[0].DeviceCategory);
          }
      }
  }
  </code></pre>
  
  <p><code>BaseViewModel</code> - This was from a Code with Mosh Tutorial</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace Monger.ViewModel
  {
      public class BaseViewModel : INotifyPropertyChanged
      {
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
          {
              PropertyChanged?.Invoke(this, new 
                  PropertyChangedEventArgs(propertyName));
          }
  
          protected void SetValue&lt;T&gt;(ref T backingField, T Value, [CallerMemberName] string propertyName = null)
          {
              if (EqualityComparer&lt;T&gt;.Default.Equals(backingField, Value))
                  return;
              backingField = Value;
              OnPropertyChanged(propertyName);
          }
      }
  }
  </code></pre>