Command
ReferencesRemarks: Commands allow you to create a single class that can be used for both menu and tool items.
Constructors
Properties
CommandParameter
#Gets or sets the parameter to pass to the Command when executing or determining its CanExecute state.
Value: The command parameter.
DataContext
#Gets or sets the data context for this widget for binding
Remarks: Subclasses may override the standard behaviour so that hierarchy of widgets can be taken into account. For example, a Control may return the data context of a parent, if it is not set explicitly.
Implements: DataContext
DelegatedCommand
#Gets or sets a command to delegate to when the command is invoked.
Remarks: This allows you to use a command to define menu/toolbar items or other functionality, and use a delegated command to chain to when invoked. This is especially useful when binding to a view model, you can do something like the following:
var myCommand = new Command { MenuText = "My Command", Parent = myForm };
myCommand.BindDataContext(c => c.DelegatedCommand, (MyModel m) => m.MyModelCommand);
//...
myForm.DataContext = new MyModel { MyModelCommand = ... }; The ICommand.CanExecute(object) will also used to set the enabled/disabled state of the current command.Value: The command to invoke.
Enabled
#Gets or sets a value indicating whether this Command is enabled.
Value:
true if enabled; otherwise, false.ID
#Gets or sets the ID of the command
Remarks: This can be used to identify a command.
Value: The command ID.
Image
#Gets or sets the image for the menu or tool item.
Remarks: On some platforms, the menu bar does not show the image by default (e.g. OS X). You can override this behaviour using a style on the handler.
Value: The image for menu or tool items.
IsDataContextChanging
#Gets a value indicating that the DataContext property is changing.
Remarks: This can be used to determine when to allow certain logic during the update of the data context. It is used to disable binding setters on the model when the data context changes so that a binding does not cause the view model to be updated when the state hasn't been fully set yet.
Value:
true if the DataContext is currently changing, false otherwise.Implements: IsDataContextChanging
Parent
#Gets the parent widget which this widget has been added to, if any
Value: The parent widget, or null if there is no parent
Methods
CreateToolItem
#Creates a new tool item attached to this command.
Returns: The tool item for the command.
OnDataContextChanged
#Raises the DataContextChanged event
Remarks: Implementors may override this to fire this event on child widgets in a heirarchy. This allows a control to be bound to its own DataContext, which would be set on one of the parent control(s).
Parameters:
| e (EventArgs) | Event arguments |
Events
DataContextChanged
#Event to handle when the DataContext has changed
Remarks: This may be fired in the event of a parent in the hierarchy setting the data context. For example, the Container widget fires this event when it's event is fired.
Implements: DataContextChanged