How can i create delete event for button in ListView ?

ShahabuddinVansiwalaShahabuddinVansiwala USMember ✭✭
edited November 2015 in Xamarin.Forms

Hello,

How can i create delete event for button in ListView with Yes/No Popup Box ?
Because i have already created listView.ItemSelected event for edit.
In this Program When i click on list of Name then Navigate to Registration Page for update.
But i want to create Delete event for button with Yes/No Popup box on same page .

What can i do ??

Answers

  • JacobPoulsen_JacobPoulsen_ DKMember ✭✭✭

    I have previous used two ways for this, both with succes.

    One way is to use the MessagingCenter: https://developer.xamarin.com/guides/cross-platform/xamarin-forms/messaging-center/ and the subscribe from either the ContentPage or Listview, and use your custom Cell to send.

    The other way would be creating your custom cell with a Page in the constructor like this:

    public class CustomCell : ViewCell
    {
        public CustomCell(MyContentPage myContentPage)
        {
        }
        // More stuff
    
        //When delete button is pressed, use this   
        //myContentPage.DisplayAlert("","","");
    }
    

    Then i could use the cell like this on MyContentPage which is the page that contains the ListView:

    public class MyContentPage : ContentPage
    {
        public MyContentPage()
        {
            // Setup listview..
            myListview.ItemTemplate = new DataTemplate(new CustomCell(this));
        }
    }
    

    I bet there are other ways of doing this, but so far this has worked just fine :)

Sign In or Register to comment.