Skip to content

},System.Linq.Expressions.Expression{System.Func{--0,--3}},System.Linq.Expressions.Expression{System.Func{--1,--4}},System.String)} },System.Linq.Expressions.Expression{System.Func{--0,--3}},System.Linq.Expressions.Expression{System.Func{--1,--4}})} },System.Linq.Expressions.Expression{System.Func{--0,--3}},System.IObservable{--4},System.String)} },System.Linq.Expressions.Expression{System.Func{--0,--3}},System.IObservable{--4})}

ICommandBinderImplementation.BindCommand(TViewModel?, TView, Expression>, Expression>, Expression>, string?) method

Defined in

Type: ICommandBinderImplementation Namespace: ReactiveUI Assembly: ReactiveUI.Core.dll

Applies to

net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471

Overloads

  • 1. IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, Expression<Func<TViewModel, TParam?>> withParameter, string? toEvent) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class
  • 2. IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, Expression<Func<TViewModel, TParam?>> withParameter) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class
  • 3. IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, IObservable<TParam?> withParameter, string? toEvent) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class
  • 4. IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, IObservable<TParam?> withParameter) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class

1. Overload

Attributes: [RequiresUnreferencedCode("Dynamic observation uses reflection over members that may be trimmed.")]

IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, Expression<Func<TViewModel, TParam?>> withParameter, string? toEvent) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class

Summary: Binds a command from the view model to a control on the view, enabling the control to execute the command with a specified parameter when an event is raised.

Type parameters

NameDescription
TViewThe type of the view that implements the IViewFor interface.
TViewModelThe type of the view model containing the command to bind.
TPropThe type of the command property on the view model. Must implement ICommand.
TControlThe type of the control on the view to which the command will be bound.
TParamThe type of the parameter passed to the command when the event is raised.

Parameters

NameTypeDescription
viewModelTViewModel?The view model instance containing the command to bind. Necessary for type inference. Can be null if the binding should be established without an initial view model.
viewTViewThe view instance containing the control to which the command will be bound. Cannot be null.
viewModelPropertyExpression>An expression identifying the command property on the view model to bind. Cannot be null.
controlPropertyExpression>An expression identifying the control on the view to which the command will be bound. Cannot be null.
withParameterExpression>An expression specifying the parameter to pass to the command when it is executed. Cannot be null.
toEventstring?The name of the event on the control that triggers the command execution. If null, a default event is used based on the control type. If the specified event does not exist on the control, an exception may be thrown at runtime. NOTE: If this parameter is used inside WhenActivated, it's important to dispose the binding when the view is deactivated.

Returns: IReactiveBinding -- An IReactiveBinding representing the established binding between the command and the control. It will remain active until disposed.

Remarks

The binding enables the control to execute the command when the specified event is raised, and automatically manages the enabled state of the control based on the command's CanExecute state.

This method uses reflection to observe events and properties on the control, which may be affected by trimming in some deployment scenarios.

2. Overload

Attributes: [RequiresUnreferencedCode("Dynamic observation uses reflection over members that may be trimmed.")]

IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, Expression<Func<TViewModel, TParam?>> withParameter) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class

Summary: Binds a command from the view model to a control on the view, enabling the control to execute the command with a specified parameter using the default event for the control type.

Type parameters

NameDescription
TViewThe type of the view that implements the IViewFor interface.
TViewModelThe type of the view model containing the command to bind.
TPropThe type of the command property on the view model. Must implement ICommand.
TControlThe type of the control on the view to which the command will be bound.
TParamThe type of the parameter passed to the command when the event is raised.

Parameters

NameTypeDescription
viewModelTViewModel?The view model instance containing the command to bind. Necessary for type inference. Can be null if the binding should be established without an initial view model.
viewTViewThe view instance containing the control to which the command will be bound. Cannot be null.
viewModelPropertyExpression>An expression identifying the command property on the view model to bind. Cannot be null.
controlPropertyExpression>An expression identifying the control on the view to which the command will be bound. Cannot be null.
withParameterExpression>An expression specifying the parameter to pass to the command when it is executed. Cannot be null.

Returns: IReactiveBinding -- An IReactiveBinding representing the established binding between the command and the control. It will remain active until disposed.

Remarks

The binding enables the control to execute the command when the default event is raised, and automatically manages the enabled state of the control based on the command's CanExecute state.

This method uses reflection to observe events and properties on the control, which may be affected by trimming in some deployment scenarios.

3. Overload

Attributes: [RequiresUnreferencedCode("Dynamic observation uses reflection over members that may be trimmed.")]

IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, IObservable<TParam?> withParameter, string? toEvent) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class

Summary: Binds a command from the view model to a control on the view, enabling the control to execute the command with a specified parameter when an event is raised.

Type parameters

NameDescription
TViewThe type of the view that implements the IViewFor interface.
TViewModelThe type of the view model containing the command to bind.
TPropThe type of the command property on the view model. Must implement ICommand.
TControlThe type of the control on the view to which the command will be bound.
TParamThe type of the parameter passed to the command when the event is raised.

Parameters

NameTypeDescription
viewModelTViewModel?The view model instance containing the command to bind. Used for type inference. Can be null if the binding should be established without an initial view model.
viewTViewThe view instance containing the control to which the command will be bound. Cannot be null.
viewModelPropertyExpression>An expression identifying the command property on the view model to bind. Cannot be null.
controlPropertyExpression>An expression identifying the control on the view to which the command will be bound. Cannot be null.
withParameterIObservableAn observable that provides the parameter to pass to the command when it is executed. Cannot be null.
toEventstring?The name of the event on the control that triggers the command execution. If null, a default event is used based on the control type. If the specified event does not exist on the control, an exception may be thrown at runtime. NOTE: If this parameter is used inside WhenActivated, it's important to dispose the binding when the view is deactivated.

Returns: IReactiveBinding -- An IReactiveBinding representing the established binding between the command and the control. It will remain active until disposed.

Remarks

The binding enables the control to execute the command when the specified event is raised, and automatically manages the enabled state of the control based on the command's CanExecute state.

This method uses reflection to observe events and properties on the control, which may be affected by trimming in some deployment scenarios.

4. Overload

Attributes: [RequiresUnreferencedCode("Dynamic observation uses reflection over members that may be trimmed.")]

IReactiveBinding<TView, TProp> BindCommand<TView, TViewModel, TProp, TControl, TParam>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> viewModelProperty, Expression<Func<TView, TControl>> controlProperty, IObservable<TParam?> withParameter) where TView : class, IViewFor where TViewModel : class where TProp : ICommand where TControl : class

Summary: Binds a command from the view model to a control on the view, enabling the control to execute the command with a specified parameter using the default event for the control type.

Type parameters

NameDescription
TViewThe type of the view that implements the IViewFor interface.
TViewModelThe type of the view model containing the command to bind.
TPropThe type of the command property on the view model. Must implement ICommand.
TControlThe type of the control on the view to which the command will be bound.
TParamThe type of the parameter passed to the command when the event is raised.

Parameters

NameTypeDescription
viewModelTViewModel?The view model instance containing the command to bind. Used for type inference. Can be null if the binding should be established without an initial view model.
viewTViewThe view instance containing the control to which the command will be bound. Cannot be null.
viewModelPropertyExpression>An expression identifying the command property on the view model to bind. Cannot be null.
controlPropertyExpression>An expression identifying the control on the view to which the command will be bound. Cannot be null.
withParameterIObservableAn observable that provides the parameter to pass to the command when it is executed. Cannot be null.

Returns: IReactiveBinding -- An IReactiveBinding representing the established binding between the command and the control. It will remain active until disposed.

Remarks

The binding enables the control to execute the command when the default event is raised, and automatically manages the enabled state of the control based on the command's CanExecute state.

This method uses reflection to observe events and properties on the control, which may be affected by trimming in some deployment scenarios.