BindingExecuteCommandT Method (Object, ExpressionFuncT, ICommand, Object) |
Executes a command retrieved using a property commandExpression from the dataContext.
Namespace:
Eto.Forms
Assembly:
Eto (in Eto.dll) Version: 2.5.3-dev
Syntax public static void ExecuteCommand<T>(
Object dataContext,
Expression<Func<T, ICommand>> commandExpression,
Object parameter = null
)
Public Shared Sub ExecuteCommand(Of T) (
dataContext As Object,
commandExpression As Expression(Of Func(Of T, ICommand)),
Optional parameter As Object = Nothing
)
static member ExecuteCommand :
dataContext : Object *
commandExpression : Expression<Func<'T, ICommand>> *
?parameter : Object
(* Defaults:
let _parameter = defaultArg parameter null
*)
-> unit
Parameters
- dataContext
- Type: SystemObject
Data context object to get the ICommand via the commandBinding. - commandExpression
- Type: System.Linq.ExpressionsExpressionFuncT, ICommand
Property expression to get the ICommand from the data context - parameter (Optional)
- Type: SystemObject
Parameter to pass to the command when executing or checking if it can execute.
Type Parameters
- T
[Missing <typeparam name="T"/> documentation for "M:Eto.Forms.Binding.ExecuteCommand``1(System.Object,System.Linq.Expressions.Expression{System.Func{``0,System.Windows.Input.ICommand}},System.Object)"]
Remarks
This helper method is useful for binding general events to fire an
ICommand that is in your view model.
The command will only be executed if its
CanExecute(Object) returns
true.
Most controls (e.g.
Button) have a special Command parameter that can be set instead,
which takes into account the enabled state of the command and will enable/disable the control automatically.
Examples
This example will fire the MyModel.MyCommand when the mouse is down on the specified panel.
The MyModel instance is based off the panel's current DataContext.
var panel = new Panel();
panel.MouseDown += (sender, e) => Binding.ExecuteCommand(panel.DataContext, (MyModel m) => m.MyCommand);
See Also