CommandPatternAttribute

Oct 15, 2010 at 5:19 AM

I am planning on developing a CommandPatternAttribute that can be used like this:

 

class MyViewModel
{
    [CommandPattern]
    public bool CanApply { get { ... } protected set { ... NotifyPropertyChanged("CanApply"); } }
    
    [CommandPattern]
    public void Apply()
    {
        // Execute Apply...
     }
}

 

This would work similarly to the OperationContractAttribute.AsyncPattern property from WCF, but implemented with something like what you're doing with auto commands in ViewModelSupport. It would figure out the name of the command method (Apply) and match it up with the CanApply property so it can implement ICommand.CanExecute and just return the property value.

The reason that I want to do it like this is because it offers the option of using my view models in situations where commanding doesn't work, in an elegant way.

I'm just leaving this here as a suggestion in case anyone is interested in doing it before I get to it. Shouldn't be too hard to port some of the ViewModelSupport auto command code to do this. Otherwise, I will come back and write about my implementation.

Thanks.