Command

References
public class Command : IBindable, ICommand
Base command for use on either ToolBar or MenuBar
Remarks: Commands allow you to create a single class that can be used for both menu and tool items.

Constructors

Command

#
public Command(EventHandler<EventArgs> execute)
Initializes a new instance of the Command class with the specified execute handler.

Properties

Bindings

#
public BindingCollection Bindings { get; }
Gets the collection of bindings that are attached to this widget

CommandParameter

#
public object CommandParameter { get; set; }
Gets or sets the parameter to pass to the Command when executing or determining its CanExecute state.

DataContext

#
public object DataContext { get; set; }
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.
DataContext

DelegatedCommand

#
public ICommand DelegatedCommand { get; set; }
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.
The command to invoke.

Enabled

#
public virtual bool Enabled { get; set; }
Gets or sets a value indicating whether this Command is enabled.

ID

#
public string ID { get; set; }
Gets or sets the ID of the command
Remarks: This can be used to identify a command.
The command ID.

Image

#
public Image Image { get; set; }
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.
The image for menu or tool items.

IsDataContextChanging

#
public bool IsDataContextChanging { get; set; }
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.
true if the DataContext is currently changing, false otherwise.

Parent

#
public IBindable Parent { get; set; }
Gets the parent widget which this widget has been added to, if any

Properties

#
public PropertyStore Properties { get; }
Gets the dictionary of properties for this widget

Shortcut

#
public Keys Shortcut { get; set; }
Gets or sets the shortcut to trigger this command.

Tag

#
public object Tag { get; set; }
Gets or sets a user-defined tag value for this instance.

ToolBarText

#
public string ToolBarText { get; set; }
Gets or sets the tool bar text.

ToolTip

#
public string ToolTip { get; set; }
Gets or sets the tool tip on both the menu and toolbar.

Methods

CreateMenuItem

#
public virtual MenuItem CreateMenuItem()
Creates a new menu item attached to this command.

CreateToolItem

#
public virtual ToolItem CreateToolItem()
Creates a new tool item attached to this command.

OnDataContextChanged

#
protected internal virtual void OnDataContextChanged(EventArgs e)
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).
e (EventArgs)Event arguments

OnEnabledChanged

#
protected virtual void OnEnabledChanged(EventArgs e)
Raises the EnabledChanged event.

OnExecuted

#
protected virtual void OnExecuted(EventArgs e)
Raises the Executed event.

Events

DataContextChanged

#
public event EventHandler<EventArgs> 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.
DataContextChanged

Executed

#
public event EventHandler<EventArgs> Executed
Occurs when the command is executed from either the menu or toolbar.

Convertors

OperationResultDescription
implicitCommandMenuItemImplicitly converts the command to a menu item
implicitCommandToolItemImplicitly converts the command to a tool item