title: xamarin listview get selected item
body: <p>Cannot figure out a proper way get an item from ListView.</p>
  
  <p>My XAML bindings:</p>
  
  <pre><code>            &lt;ListView x:Name="MyListView" ItemTapped="MyListView_ItemTapped" HasUnevenRows="True"&gt;
              &lt;ListView.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;ViewCell&gt;
                          &lt;StackLayout&gt;
  
                              &lt;Label Text="{Binding Name}"&gt;&lt;/Label&gt;
                              &lt;Label Text="{Binding Email}"&gt;&lt;/Label&gt;
                              &lt;Image Source="{Binding PhotoUrl}" WidthRequest="20" HeightRequest="20"&gt;&lt;/Image&gt;
                          &lt;/StackLayout&gt;
                      &lt;/ViewCell&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListView.ItemTemplate&gt;
          &lt;/ListView&gt;
  </code></pre>
  
  <p>All the data gets displayed and works fine. Class is called Forums:</p>
  
  <pre><code>    [JsonProperty("results")]
      public List&lt;Result&gt; Results { get; set; }
  
      public class Result
      {
          [JsonProperty("name")]
          public string Name { get; set; }
          [JsonProperty("email")]
          public string Email { get; set; }
          [JsonProperty("photoUrl")]
          public string PhotoUrl { get; set; }
      }
  </code></pre>
  
  <p>I have made MyListView_ItemTapped Function and for now, I'm trying to display its name when the item is tapped on, but not sure what is a proper way to do it. And I always think that I'm just <strong>bodging</strong> some random things together until I get something.</p>
  
  <pre><code>        private void MyListView_ItemTapped(object sender, ItemTappedEventArgs e)
      {
  
          var index = forums.Results.IndexOf(e.Item as Forums.Result);
          DisplayAlert("Alert", forums.Results[index].Name, "OK");
  
      }
  </code></pre>
  
  <p>So if anyone could point me to the better direction or even give few better examples or just explain how should it be done.</p>