Prevent double-click from double firing a command

前端 未结 14 1859
情书的邮戳
情书的邮戳 2020-12-15 08:34

Given that you have a control that fires a command:

Is there a way to prevent the command from being fired

14条回答
  •  孤街浪徒
    2020-12-15 09:20

    You can use the EventToCommand class in the MVVMLightToolkit to prevent this.

    Handle the Click event and send it through EventToCommand from your view to your viewmodel (you can use EventTrigger to do this).
    Set MustToggleIsEnabled="True" in your view and implement a CanExecute() method in your viewmodel.
    Set CanExecute() to return false when the command starts to execute and back to true when the command is done.

    This will disable the button for the duration of processing the command.

提交回复
热议问题