This repository was archived by the owner on Aug 27, 2020. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 37
 
DelegateCommand
        Mark Smith edited this page Aug 29, 2016 
        ·
        1 revision
      
    The DelegateCommand class is an implementation of IDelegateCommand and provides an ICommand implementation based on delegates.
It comes in two variations: DelegateCommand which uses an object as the parameter type, and DelegateCommand<T> which casts the parameter to a T type.
This is a standard ICommand implementation that utilizes delegates similar to the built-in Xamarin.Forms Command class. However, this is not dependent on Xamarin.Forms so the ViewModel can avoid taking a dependency on the framework in the source code.
Tip: you should expose this from a ViewModel as an
IDelegateCommandso it can be replaced for testing.
- 
RaiseCanExecuteChanged: raises theCanExecuteChangedevent. 
public class MyViewModel : SimpleViewModel
{
   public IDelegateCommand DoSomething { get; private set; }
   public MyViewModel()
   {
      DoSomething = new DelegateCommand<string>(OnDoSomething, s => CanDoSomething == true);
   }
   private void DoSomething(string parameter)
   {
     ...
   }
}