title: Accessing an element inside of a Collectionview datatemplate in Xamarin.Forms
body: <p>I am fairly new to Xamarin.Forms and am attempting to access a child element of a <strong>CollectionView DataTemplate</strong>. </p>
  
  <p>The <strong>DataTemplate</strong> contains a horizontal <strong>StackLayout</strong> consisting of a <strong>Checkbox</strong> and a <strong>Label</strong>. </p>
  
  <p>What I would like to do is to make the <strong>Checkbox</strong>'s <code>IsChecked</code> property equal to <code>true</code> whenever the <strong>CollectionView</strong> element is selected, in order to show the <strong>Checkbox</strong> as checked when an element is selected. </p>
  
  <p>The highest number of elements that I will ever have in this <strong>CollectionView</strong> are 2.</p>
  
  <p>Here is some code to illustrate what I am trying to do:</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:d="http://xamarin.com/schemas/2014/forms/design"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="CheckBoxExample.MainPage"&gt;
  
    &lt;StackLayout&gt;
      &lt;!-- Place new controls here --&gt;
      &lt;Label
        Text="Welcome to Xamarin.Forms!"
        HorizontalOptions="Center"
        VerticalOptions="CenterAndExpand" /&gt;
      &lt;Frame&gt;
        &lt;CollectionView
          ItemsSource="{Binding Customers}"&gt;
          &lt;CollectionView.ItemTemplate&gt;
            &lt;DataTemplate&gt;
              &lt;StackLayout
                Orientation="Horizontal"&gt;
                &lt;CheckBox
                  IsChecked="" /&gt;
                &lt;Label
                  Text="{Binding .}"
                  VerticalOptions="Center" /&gt;
              &lt;/StackLayout&gt;
            &lt;/DataTemplate&gt;
          &lt;/CollectionView.ItemTemplate&gt;
        &lt;/CollectionView&gt;
      &lt;/Frame&gt;
  
    &lt;/StackLayout&gt;
  
  &lt;/ContentPage&gt;
  </code></pre>