Register an ICommand in the ViewModel for Silverlight 4 and WPF4

Available as an extension method of INotifyPropertyChanged interface, it's possible to register an ICommand in just one line of code.

public ICommand UpdateCustomerCommand
{
  get
    {
      return
        this
          .RegisterCommand(PerformUpdateCustomer)
          .Evaluate();
    }
}

All that you have to do is pass an action to perform and, optionally, a condition that indicates when the action can be performed.
public ICommand UpdateCustomerCommand
{
  get
    {
      return
        this
          .RegisterCommand(PerformUpdateCustomer)
          .CanExecute(CanUpdateCustomer)
          .Evaluate();
    }
}

In addition, to boost up the performance of the application, you can specify the properties to monitor.
In this case the command state will be re-evaluated only when the specified properties are changed.

public ICommand MakeLastNameUpperCaseCommand
{
  get
    {
      return
        this
          .RegisterCommand(PerformMakeLastNameUpperCase)
          .CanExecute(CanMakeLastNameUpperCase)
          .MonitorProperty(p => p.LastName)
          .Evaluate();
    }
}

Last edited Aug 31, 2010 at 11:33 PM by teoarch, version 8

Comments

No comments yet.