ListView ItemTapped and a Button

Laura83Laura83 USMember ✭✭

Hi there. I have a ListView with a ItemTapped gesture method and it works, but now I have to add a button within each item.
If I click on the item, I want to do something.
If I click on button in the item, I want to do something else, depending by the object that the item contains.
How do that?


  • Vamsi.KatakamVamsi.Katakam USMember ✭✭

    if u have any unique value then just bind the value to button.
    Button.SetBinding(Button.CommandParameterProperty, new Binding("Your Uniqe ID"));


    get that id in button click event like

    var mi = ((Button)sender);
    var id= (mi != null) ? Convert.ToInt32(mi.CommandParameter) : 0;

    hope it is usefull..

  • Laura83Laura83 USMember ✭✭
    edited July 2016

    Hi, and thanks for reply.
    I haven't a unique value. I want to bind each button of the listview with a specific Object depending by the element in wich the button is.
    Also I'm using xaml instead of c#
    I don't know if my words are clear enough, sorry for my bad english.

  • Laura83Laura83 USMember ✭✭

    Never Mind. I solved binding the button with another element in the view, similar to your advice.
    Thank you!

  • SurbhiAroraSurbhiArora USMember ✭✭

    @Laura83 Can you please explain , how you did? I also want the same... not in xaml but in xaml.cs

  • Laura83Laura83 USMember ✭✭

    @SurbhiArora I finally understood how to use MVVM architecture correctly and Commanding.
    For Example:

    hope it helps

Sign In or Register to comment.