how reference ItemTappedEventArgs with stacklayout

In a stacklayout within a datatemplate of a list I want to get the id of the item that I select from the stacklayout

Tagged:

Answers

  • suraj007suraj007 Member ✭✭✭

    private string selectedItem;

    private void MyCategory_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
    var selectedCategory = e.SelectedItem as Catergory; /////Catergory is list model name.

    if (selectedCategory != null)
        selectedItem = selectedCategory.Id;
    

    }

  • LandLuLandLu Member, Xamarin Team Xamurai

    Register the ItemTapped of your listview:

    <ListView ItemsSource="{Binding Items}" ItemTapped="ListView_ItemTapped">
        ...
    </ListView>
    

    You can access the item in the event:

    private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        var model = (Model)e.Item;
        // Get the ID here
        // model.id;
    }
    
  • Ashish_sharmaAshish_sharma INMember ✭✭✭
    edited October 4

    You have to create Stack-layout tap-gesture Event and when u tap on any item then u get id of selected items .

Sign In or Register to comment.