title: Xamarin Control Template with two pickers events handle
body: <p>I have a xamarin control template with two pickers and is added in app.xml, I use that template in two pages "Home &amp; Detail", i want to:</p>
  
  <ol>
  <li>How to maintain pickers selected index across all pages that use this template.</li>
  <li>How to handle selectedindexchange event for both pickers across all pages, ex: (When index change set label text with selected text)</li>
  </ol>
  
  <p>PS: my pickers items sources will be set at run-time from my model. and based on 1st picker selection item source for 2nd picker will change.</p>
  
  <p><strong>app.xaml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SimpleTheme.App"&gt;
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ControlTemplate x:Key="ActiveProfileTemplate"&gt;
                  &lt;Grid Padding="5,0,0,0" BackgroundColor="#f7f6fb"&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="0.1*" /&gt;
                          &lt;RowDefinition Height="0.8*" /&gt;
                      &lt;/Grid.RowDefinitions&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto" /&gt;
                          &lt;ColumnDefinition Width="*" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;BoxView Grid.ColumnSpan="2"/&gt;
                      &lt;Picker x:Name="FirstPicker" Title="FirstPicker" SelectedIndex="{TemplateBinding Parent.FirstPickerSelectedIndex}" Grid.Column="0" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="180" FontSize="Small" TextColor="#214189"&gt;
                          &lt;Picker.Items&gt;
                              &lt;x:String&gt;FirstPicker_1&lt;/x:String&gt;
                              &lt;x:String&gt;FirstPicker_2&lt;/x:String&gt;
                              &lt;x:String&gt;FirstPicker_3&lt;/x:String&gt;
                              &lt;x:String&gt;FirstPicker_4&lt;/x:String&gt;
                              &lt;x:String&gt;FirstPicker_5&lt;/x:String&gt;
                          &lt;/Picker.Items&gt;
                      &lt;/Picker&gt;
                      &lt;Picker x:Name="SecondPicker" Title="SecondPicker" SelectedIndex="{TemplateBinding Parent.SecondPickerSelectedIndex}" Grid.Column="1" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="210" FontSize="Small" TextColor="#214189" &gt;
                          &lt;Picker.Items&gt;
                              &lt;x:String&gt;SecondPicker_1&lt;/x:String&gt;
                              &lt;x:String&gt;SecondPicker_2&lt;/x:String&gt;
                              &lt;x:String&gt;SecondPicker_3&lt;/x:String&gt;
                              &lt;x:String&gt;SecondPicker_4&lt;/x:String&gt;
                              &lt;x:String&gt;SecondPicker_5&lt;/x:String&gt;
                          &lt;/Picker.Items&gt;
                      &lt;/Picker&gt;
                      &lt;ContentPresenter Grid.Row="1" Grid.ColumnSpan="2"/&gt;
                  &lt;/Grid&gt;
              &lt;/ControlTemplate&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p><strong>HomePage.xaml</strong></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" x:Class="SimpleTheme.HomePage"&gt;
      &lt;ContentView x:Name="contentView" Padding="0,20,0,0" ControlTemplate="{StaticResource ActiveProfileTemplate}"&gt;
          &lt;StackLayout VerticalOptions="CenterAndExpand"&gt;
              &lt;Label Text="Welcome to the HomePage!" HorizontalOptions="Center" /&gt;
              &lt;Label x:Name="lbl_firstpicker" Text="First Picker Selected Item" HorizontalOptions="Center" TextColor="DarkRed"/&gt;
              &lt;Label x:Name="lbl_secondpicker" Text="Second Picker Selected Item" HorizontalOptions="Center" TextColor="DarkRed"/&gt;
          &lt;/StackLayout&gt;
      &lt;/ContentView&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p><strong>HomePage.cs</strong></p>
  
  <pre><code>public partial class HomePage : ContentPage
  {
      public static readonly BindableProperty FirstPickerSelectedIndexProperty = BindableProperty.Create(
          "FirstPickerSelectedIndex",
          typeof(int),
          typeof(HomePage),
          2);
      public static readonly BindableProperty SecondPickerSelectedIndexProperty = BindableProperty.Create(
          "SecondPickerSelectedIndex",
          typeof(int),
          typeof(HomePage),
          3);
  
      public int FirstPickerSelectedIndex =&gt; (int)GetValue(FirstPickerSelectedIndexProperty);
      public int SecondPickerSelectedIndex =&gt; (int)GetValue(SecondPickerSelectedIndexProperty);
  
      public HomePage()
      {
              InitializeComponent();
       }
  }
  </code></pre>
  
  <p><strong>DetailPage.xaml</strong></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"
               x:Class="SimpleTheme.DetailPage"&gt;
      &lt;ContentView x:Name="contentView" Padding="0,20,0,0" ControlTemplate="{StaticResource ActiveProfileTemplate}"&gt;
          &lt;StackLayout VerticalOptions="CenterAndExpand"&gt;
              &lt;Label Text="Welcome to the DetailPage!" HorizontalOptions="Center" /&gt;
              &lt;Label x:Name="lbl_firstpicker" Text="First Picker Selected Item" HorizontalOptions="Center" TextColor="Teal" /&gt;
              &lt;Label x:Name="lbl_secondpicker" Text="Second Picker Selected Item" HorizontalOptions="Center" TextColor="Teal" /&gt;
          &lt;/StackLayout&gt;
      &lt;/ContentView&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wMPKX.png" rel="nofollow noreferrer">Screenshot</a>
  <a href="https://i.stack.imgur.com/Yg9sL.png" rel="nofollow noreferrer">Screenshot</a></p>