title: Xamarin Forms : Access list data when click of a Button inside listview-viewcell
body: <p>I have a button inside listview-viewcell. For the button, I am using clicked event. So on click of the button, I need the details of the selected list item like the first name, email etc. I tried like following:</p>
  
  <p>Xaml code:</p>
  
  <pre><code>  &lt;ListView x:Name="MyDirectories"
                    HasUnevenRows="True"&gt;
               &lt;ListView.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;ViewCell&gt;
                          &lt;ViewCell.View&gt;
                                   &lt;Button
                                          BorderRadius="25"
                                          HeightRequest="40"
                                          WidthRequest="150"
                                          TextColor="White"
                                          HorizontalOptions="CenterAndExpand"
                                          Font="Bold,15"
                                          Margin="0,0,0,5"
                                          BackgroundColor="#004F7E" 
                                          Clicked="MoreDetails"
                                          Text="More Details"/&gt;
                              &lt;/StackLayout&gt;
                          &lt;/ViewCell.View&gt;
                      &lt;/ViewCell&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListView.ItemTemplate&gt;
           &lt;/ListView&gt;
  </code></pre>
  
  <p>Xaml.cs code:</p>
  
  <pre><code>       public class MyListItemEventArgs : EventArgs
          {
              public UserProfileTO MyItem { get; set; }
              public MyListItemEventArgs(UserProfileTO item)
              {
                  this.MyItem = item;
              }
          }
  
         public void MoreDetails(Object sender, MyListItemEventArgs args)
          {
               var item = args.MyItem;
              if (item != null)
              {
                  Debug.WriteLine("Firstname:&gt;"+item.firstName);
              }
         }
  </code></pre>
  
  <p>When I run getting InvalidCastException: Specified cast is not valid.
  Anybody, please suggest any other solution.
  Thanks in advance.</p>