title: Reusable ContentView in Xamarin forms
body: <p>I have created a contentview separately, so that I can reuse the same in different ContentPage. </p>
  
  <p>Here is my ContentView.XAML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:custom="clr-namespace:MyMXLibrary.Helpers"
           x:Class="MyMXLibrary.Views.AlertView" 
           x:Name="this"&gt;
  &lt;ContentView.Content&gt;
      &lt;Frame VerticalOptions="Center" HorizontalOptions="Center"&gt;
          &lt;StackLayout&gt;
              &lt;Label Text="{Binding Source={x:Reference this}, Path=Heading}"/&gt;
              &lt;Label Text="{Binding Source={x:Reference this}, Path=Message}"/&gt;&lt;Label Text="Cancel"&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer Command="{Binding CancelCommand}" /&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
              &lt;Label Text="Ok"&gt;
                  &lt;Label.GestureRecognizers&gt;
                      &lt;TapGestureRecognizer Command="{Binding ProceedCommand}" /&gt;
                  &lt;/Label.GestureRecognizers&gt;
              &lt;/Label&gt;
          &lt;/StackLayout&gt;
      &lt;/Frame&gt;
  &lt;/ContentView.Content&gt;&lt;/ContentView&gt;
  </code></pre>
  
  <p>Here is my ContentView.Xaml.cs</p>
  
  <pre><code> public partial class AlertView : ContentView
  {
      public static readonly BindableProperty HeadingTextProperty = BindableProperty.Create(nameof(Heading), typeof(string), typeof(Label));
       public static readonly BindableProperty MessageTextProperty = BindableProperty.Create(nameof(Message), typeof(string), typeof(Label));
  
      public string Heading { get { return (string)GetValue(HeadingTextProperty); } set { SetValue(HeadingTextProperty, value); } }
      public string Message { get { return (string)GetValue(MessageTextProperty); } set { SetValue(MessageTextProperty, value); } }
  
      public AlertView()
      {
          InitializeComponent();
      }      
  }
  </code></pre>
  
  <p>Here is my sample ContentPage.Xaml where I'm planning to reuse the above created content view.</p>
  
  <pre><code>&lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:alert="clr-namespace:MyMXLibrary.Views"
           x:Class="MyMXLibrary.Views.MyPage"
           Title="MyPage"&gt;&lt;ContentPage.Content&gt;&lt;ContentView &gt;
        &lt;alert:AlertView Heading="Test" Message="Sample" &gt;&lt;/alert:AlertView&gt;&lt;/ContentView&gt;&lt;/ContentPage.Content&gt;&lt;/ContentPage&gt;
  </code></pre>
  
  <p>it's working fine if  I use a static value. But instead, if I bind the value </p>
  
  <pre><code>&lt;alert:AlertView Heading="Test" Message="{Binding sample}" &gt;&lt;/alert:AlertView&gt;
  </code></pre>
  
  <p>I'm getting error </p>
  
  <pre><code>No property, bindable property, or event found for 'Message', or mismatching type between value and property
  </code></pre>
  
  <p>How can I do the Binding here. Since my value is unknown I cannot assign a stactic value in XAML, I have to go with Binding only. 
  What Should I do here to bind the value, please help me. </p>