Reply to comment

MakeCommand

You can handle button-click events in the view model. Expose a property of type ICommand. Update Controls will implement the ICommand interface for you. Use the MakeCommand factory, and pass a delegate into the “Do” method.

public ICommand AddPerson
{
    get
    {
        return MakeCommand
            .Do(delegate
            {
                _selection.SelectedPerson = _document.NewPerson();
            });
    }
}

Some commands are not always enabled. Express the conditions under which your command is enabled by passing a lambda expression to the “When” method.

public ICommand DeletePerson
{
    get
    {
        return MakeCommand
            .When(() => _selection.SelectedPerson != null)
            .Do(delegate
            {
                _document.DeletePerson(_selection.SelectedPerson);
            });
    }
}

Data bind the property to the button’s Command. When the condition changes, the button will be enabled or disabled. And when the user clicks the button, if the condition is met, it will call the delegate in your view model.

Reply

By submitting this form, you accept the Mollom privacy policy.