title: Xamarin.Forms binding does not work
body: <p>I try to rewrite my UWP C# app for Windows10 to Xamarin app using XAML. But Binding (<strong><em>for example here in ListView ItemSource=...</em></strong>) is not working for me and I don´t know why. </p>
  
  <blockquote>
    <p><em>Visual Studio tells me, Cannot Resolve Symbol Recording due to unknown Data Context.</em></p>
  </blockquote>
  
  <p>Here is my XAML (<strong>MainPage.xaml</strong>) for testing purpose:</p>
  
  <pre><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:local="clr-namespace:XamarinTest;assembly=XamarinTest"
               x:Class="XamarinTest.MainPage"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto" /&gt;
              &lt;RowDefinition Height="*" /&gt;
              &lt;RowDefinition Height="100" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="Auto" /&gt;
              &lt;ColumnDefinition Width="*" /&gt;
              &lt;ColumnDefinition Width="100" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;ListView x:Name="listView" IsVisible="false" ItemsSource="{Binding Recording}"&gt;
              &lt;ListView.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;ViewCell&gt;
                          &lt;ViewCell.View&gt;
                              &lt;StackLayout Orientation="Horizontal"&gt;
                                  &lt;Image Source="Accept" WidthRequest="40" HeightRequest="40" /&gt;
                                  &lt;StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand"&gt;
                                      &lt;Label Text="TEST" HorizontalOptions="FillAndExpand" /&gt;
                                      &lt;Label Text="TEST" /&gt;
                                  &lt;/StackLayout&gt;
                              &lt;/StackLayout&gt;
                          &lt;/ViewCell.View&gt;
                      &lt;/ViewCell&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListView.ItemTemplate&gt;
          &lt;/ListView&gt;
      &lt;/Grid&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>Here is C# (<strong>MainPage.xaml.cs</strong>):</p>
  
  <pre><code>namespace XamarinTest
  {
      public partial class MainPage : ContentPage
      {
          public MainPage()
          {
              this.InitializeComponent();
              this.AllTestViewModel = new RecordingViewModel();
              this.BindingContext = AllTestViewModel;                
          }
          public RecordingViewModel AllTestViewModel { get; set; }
      }
  }
  </code></pre>
  
  <p>And finally ViewModel (<strong>RecordingViewModel.cs</strong>):</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Collections.ObjectModel;
  using System.Collections.Specialized;
  using System.ComponentModel;
  using System.Linq;
  using System.Runtime.CompilerServices;
  using System.Text;
  using System.Threading.Tasks;
  using XamarinTest.Model;
  
  namespace XamarinTest.ViewModel
  {
      public class RecordingViewModel : INotifyPropertyChanged
      {
          public ObservableCollection&lt;Recording&gt; Recordings { get; } = new TrulyObservableCollection&lt;Recording&gt;();
  
          public RecordingViewModel()
          {
              Recordings.Add(new RecordingTest2()
              {
                  TestName = "Test 1",
                  TestNote = "Vytvoreni DB",
                  TestTime = new TimeSpan(0, 0, 0)
              });
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
          {
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
          }
      }
      public sealed class TrulyObservableCollection&lt;T&gt; : ObservableCollection&lt;T&gt;
          where T : INotifyPropertyChanged
      {
          public TrulyObservableCollection()
          {
              CollectionChanged += FullObservableCollectionCollectionChanged;
          }
  
          public TrulyObservableCollection(IEnumerable&lt;T&gt; pItems) : this()
          {
              foreach (var item in pItems)
              {
                  this.Add(item);
              }
          }
  
          private void FullObservableCollectionCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
          {
              if (e.NewItems != null)
              {
                  foreach (Object item in e.NewItems)
                  {
                      ((INotifyPropertyChanged)item).PropertyChanged += ItemPropertyChanged;
                  }
              }
              if (e.OldItems != null)
              {
                  foreach (Object item in e.OldItems)
                  {
                      ((INotifyPropertyChanged)item).PropertyChanged -= ItemPropertyChanged;
                  }
              }
          }
  
          private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
          {
              NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, sender, sender, IndexOf((T)sender));
              OnCollectionChanged(args);
          }
      }
  }
  </code></pre>
  
  <p>Everything (models and viewmodels) are working in native UWP Windows 10 app. Only the Binding and making same view is problem in Xamarin. Could someone please help with binding? 
  Thx.</p>
  
  <h2>EDIT</h2>
  
  <p><strong>Recording.cs</strong> is here: </p>
  
  <pre><code>using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace XamarinTest.Model
  {
      public abstract class Recording : INotifyPropertyChanged
      {
          public event PropertyChangedEventHandler PropertyChanged;
          public string TestName { get; set; }
          private TimeSpan _testTime;
          private string _testNote;
          private string _actualIco = "Play";
          private bool _isActive = false;
          private bool _enabled = true;
          public double IcoOpacity { get; private set; } = 1.0;
          public string ActualIco
          {
              get =&gt; _actualIco;
              set
              {
                  if (_actualIco == null) _actualIco = "Admin";
                  _actualIco = value;
                  NotifyPropertyChanged("ActualIco");
              }
          }
          public bool IsActive
          {
              get =&gt; _isActive;
              set
              {
                  if (_isActive == value) return;
                  _isActive = value;
                  IcoOpacity = !value ? 1.0 : 0.3;
                  NotifyPropertyChanged("IsActive");
                  NotifyPropertyChanged("IcoOpacity");
              }
          }
          public bool Enabled
          {
              get =&gt; _enabled;
              set
              {
                  if (_enabled == value) return;
                  _enabled = value;
                  NotifyPropertyChanged("Enabled");
              }
          }
          public string TestNote
          {
              get =&gt; _testNote;
              set
              {
                  if (_testNote == value) return;
                  _testNote = value;
                  NotifyPropertyChanged("TestNote");
              }
          }
          public TimeSpan TestTime
          {
              get =&gt; _testTime;
              set
              {
                  if (_testTime == value) return;
                  _testTime = value;
                  NotifyPropertyChanged("TestTime");
              }
          }
  
          protected Recording()
          {
              TestName = "Unkonwn";
              TestNote = "";
              _testTime = new TimeSpan(0, 0, 0);
          }
  
          protected Recording(string testName, string testNote, TimeSpan testTime)
          {
              TestName = testName;
              TestNote = testNote;
              _testTime = testTime;
          }
          public string OneLineSummary =&gt; $"{TestName}, finished: "
                                          + TestTime;
  
          private void NotifyPropertyChanged(string propertyName = "")
          {
              var handler = PropertyChanged;
              handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
          }
  
          public abstract bool playTest();
  
      }
  }
  </code></pre>
  
  <p>I tried add DataContext in XAML (postet in origin question), because of intellisence like this:</p>
  
  <pre><code>xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  mc:Ignorable="d"
  xmlns:dvm="clr-namespace:XamarinTest.ViewModel"
  xmlns:system="clr-namespace:System;assembly=System.Runtime"
  d:DataContext="{system:Type dvm:RecordingViewModel}"
  </code></pre>
  
  <p>and this to Grid:</p>
  
  <pre><code>&lt;Label Text="{Binding Recordings[0].TestName}" Grid.Row="0" Grid.Column="2" /&gt;
  </code></pre>
  
  <p>IntelliSence is OK, but text doesn´t show in app.</p>