ICommand
interface is the canonical way to expose commands from a ViewModel that is bound to a View. They come with a few caveats:ICommand
implementation is not worth it.ICommand
interface reference WPF types with the risk of complicating the required testing infrastructure.DoSomething
method can be bound to a Button
on the View in the following manner:AutoCommandBinding
markup extension will dynamically build a DelegateCommand that wraps at runtime the method invocation.ICommand
interface exposes a CanExecute(object)
method that the WPF inteface can call to detect if the command is available in the current context and thus decide if the WPF element bound to a command should be enabled or not. Using the same approach as above a ViewModel can expose a bool
property as following:Can
. No changes to the XAML markup are required.Can*
boolean property whenever we decide the command status changes. We can leverage the power of Radical properties metadata, and specifically the cascade changes notification feature as following:SelectedEntity
property changes a INotifyPropertyChanged.PropertyChanged
event is raised also for the CanEdit
property, thus WPF reevaluates the property and based on the boolean result the bound command will be enabled or not.http://schemas.radicalframework.com/windows/markup
xml namespace.