locked
How can i create delete event for button in ListView ? RRS feed

  • Question

  • User169972 posted

    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 ??

    Monday, November 9, 2015 6:30 AM

All replies

  • User105885 posted

    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 :)

    Monday, November 9, 2015 7:34 AM