Button's Command fired multiple time inside ListView

I'm implementing a custom ViewCell in xaml that binds to a custom model that looks something like this:

public class MyClass : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    Command _EditCommand;
    public Command EditCommand { 
        get {       
            return _EditCommand??(_EditCommand = new Command(()=>{
                NavigateToEditPage();
            }));            
        } 
    }
    ....
}

In xaml, the button's command property binds to the EditCommand as seen above (for each item in listview)

<Button Command="{Binding EditCommand}" Text="Edit" FontSize="11" BackgroundColor="#65a873" TextColor="White" />

When I open the ListView for the first time, everything works fine. However, when I navigate back to previous page (hitting back button, android or iOS) and then go the page containing this ListView again, the edit button will fire twice (it navigates to the EditPage twice basically).

What could possibly be causing this issue and how would I fix it? I read up on google and people said it might have something to do with listview reusing the cell so it adds extra event handler to the same viewcell.

Sign In or Register to comment.