title: How can I make a ViewModel for a Xamarin Forms template?
body: <p>I have Template1 that inherits from ContentView. For the purpose of this question I removed a lot of things in the template to make it simple. </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:local="clr-namespace:Japanese;assembly=Japanese" x:Class="Japanese.Template1" x:Name="this"&gt;
     &lt;Label Grid.Column="0" Text="{Binding Text, Source={x:Reference this}}" /&gt;
  
  &lt;/ContentView&gt;
  </code></pre>
  
  <p>and the Template1 C# back end</p>
  
  <pre><code>namespace Japanese
  {
      public partial class Template1 : ContentView
      {
          public CardOrderTemplate()
          {
              InitializeComponent();
          }
      }
  }
  </code></pre>
  
  <p>I would like this template to share bindings in this class and so I tried some different ways to do this but none seem to work.  Here's what I was trying. Not sure but I guess I need something like a ViewModel for the template but I am not sure how I could go about implementing this.</p>
  
  <pre><code>namespace Japanese
  {
      public class SegBase : ContentView
      {
  
           public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(SegTemplate), default(string));
      public string Text
      {
          get { return (string)GetValue(TextProperty); }
          set { SetValue(TextProperty, value); }
      }
      }
  }
  </code></pre>
  
  <p>Does anyone know how I can do this? I tried making the Template1 class inherit from SegBase but it gives me an error because the XAML is a type ContentView and the C# is not inheriting from ContentView.</p>