Commands

Jounce supports commanding through IActionCommand and the implementation, ActionCommand.

ActionCommand<T> : IActionCommand<T> : IActionCommand : ICommand

This is similar to the DelegateCommand introduced by Prism, however you can construct your action and condition delegates (or create it with nothing and it will simply default to always true and "do nothing.") There is also an option to override the action which sets a flag that can be interrogated for commands that may transform over time. The "RaiseExecuteChanged" is used to notify when the condition for the command has changed.

public IActionCommand<MyEntity> SaveCommand { get; private set; }

public MyConstructor()
{
   SaveCommand = new ActionCommand<MyEntity>( entity => Service.Save(entity), entity=>IsValid(entity) );
}

Last edited Mar 27, 2011 at 2:59 PM by jeremylikness, version 3

Comments

francisdev10 Feb 6, 2012 at 4:23 PM 
HI how can i capture the itemclickeventarguments in my Viewmodel

ksunair Feb 28, 2011 at 1:35 PM 
Ah I see RaiseExecuteChanged event.

ksunair Feb 28, 2011 at 1:29 PM 
I created a command for enabling save using code like the following

public void SaveData(string parameter)
{
}
public bool CanSaveData(string parameter)
{
if (DataCollection != null)
return DataCollection.HasChanges;
else
return false;
}

In my view I bound the command. First time when it runs, the button is disabled correctly. Now when I make changes to the collection, I rise an event to viewmode that data changed and I run CanSaveData again and it changes to true. But the changes does not reflect on GUI. I even recreated the save command but the button is not getting enabled. Am I missing something here?