1

I've got Button in Windows Phone project written in MVVM. Problem is that when I double press that button I will run my method twice, or more times. How to avoid that?

That's implementation:

XAML View

<Button Command="{Binding MyCommand}" />

ViewModel

private readonly Command myButtonClick;
public ICommand MyCommand{ get { return myButtonClick; } }

{
   myButtonClick= new Command(MyMethod);
}
private async void MyMethod()
{
   // do work
}
boski
  • 1,106
  • 3
  • 21
  • 44
  • http://stackoverflow.com/questions/841332/prevent-double-click-from-double-firing-a-command – Mat Jul 03 '15 at 06:42

1 Answers1

3

The best way is to implement DelegateCommand, and check whether the button can be executed in CanExecute function. (See this question)

Another way is disabling the button after button click and enabling when operation finishes.

Community
  • 1
  • 1
daryal
  • 14,643
  • 4
  • 38
  • 54