title: Xamarin.Forms access Binding object data
body: <p>I want to make a label that will extract the name or some other data of the bound item.</p>
  
  <pre><code>[Display(Description = "Gimme your goddamm first name will ya")]
  public string FirstName { get; set; }
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public class TitleLabel : ContentView
  {
    public Label Label { get; } = new Label();
    public TitleLabel()
    {
      //TODO ensure Content is not accessed manually
      Content = Label;
    }
    protected override void OnBindingContextChanged() =&gt;
      Label.Text = GetPropertyTitle();
  
  
    string GetPropertyTitle()
    {
      var bcp = BindingContextProperty;
  
      //pseudo:
      var binding = GetBinding(bcp);
      var obj = binding.Object;
      var propertyName = binding.Path;
      var propertyInfo = obj.GetType().GetTypeInfo().DeclaredMembers
        .SingleOrDefault(m =&gt; m.Name == propertyName);
      if (propertyInfo == null)
        throw new InvalidOperationException();
  
      return propertyInfo.GetCustomAttribute&lt;DisplayAttribute&gt;().Description;
    }
  }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;my:TitleLabel Text="{Binding FirstName}" /&gt;
  </code></pre>
  
  <p>Rendered result:</p>
  
  <pre><code>&lt;my:TitleLabel Text="Gimme your goddamm first name will ya" /&gt;
  </code></pre>