title: Xamarin Forms: How to access button name in XAML from C#?
body: <p>I have the following XAML markup:</p>
  
  <pre><code>&lt;ListView x:Name="wordsListView"&gt;
     &lt;ListView.ItemTemplate&gt;
        &lt;DataTemplate&gt;
           &lt;ViewCell&gt;
              &lt;ViewCell.View&gt;
                 &lt;StackLayout&gt;
                    &lt;Label Text="{Binding Keyword}" /&gt;
                    &lt;Button Text="Click Me" x:Name="randomButton"&gt;&lt;/Button&gt;
                 &lt;/StackLayout&gt;
              &lt;/ViewCell.View&gt;
          &lt;/ViewCell&gt;
       &lt;/DataTemplate&gt;
     &lt;/ListView.ItemTemplate&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>And in my .xaml.cs file I have the button clicked event for the <code>random</code> button defined as below:</p>
  
  <pre><code>randomButton.Clicked += (object sender, EventArgs e) =&gt;
  {
      a = rand.Next(words.Count);
      word = words[a];
  };
  </code></pre>
  
  <p>But somehow when I build my project I kept getting an error: <code>The name randomButton does not exists in the current context.</code> Can anyone tell me what I'm doing wrong and how it should be done?</p>