# BindCommandMixins

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/binding/mixins/trait-bindcommandmixins/

**trait** · [`ferroui-reactiveui`](/docs/0.5.0/api/ferroui-reactiveui/) · v0.5.0

```rust
trait BindCommandMixins<V: 'static>
```

`BindCommand`: binds the command a property of a view model holds to the control a property of
a view holds, rebinding when either changes. Implemented for every `Rc` of a view.

Upstream's source generator roots the command at the view's `ViewModel` when the view declares
one: the binding follows the view model the view displays, and binds nothing while there is
none. `bind_command` and its `_with_` forms do that for a view that
declares its view model (`IViewForOf<VM>`), observed as the property `ViewModel` of the view; the `_on`
forms root the command at a given view model, as for a view that does not declare one, and bind
nothing without a view model.

The command binds to `to_event` ([`ToEvent`](/docs/0.5.0/api/ferroui-reactiveui/binding/mixins/struct-toevent/)); without one, to the default event of the
control, through the registered binder with the highest affinity for the type of the control
([`CommandBinderService`](/docs/0.5.0/api/ferroui-reactiveui/binding/command_binding/struct-commandbinderservice/)). The command executes with the latest value of the command
parameter, if it can execute with it.

Deviation (DEVIATIONS.md, ReactiveUI): upstream overloads `BindCommand` by the source of the
parameter (none, an observable, an expression) and resolves the root and the event at compile
time; here each is a method of its own, the event is a [`ToEvent`](/docs/0.5.0/api/ferroui-reactiveui/binding/mixins/struct-toevent/), and the view-rooted forms
leave out upstream's `viewModel` argument, which the generated code does not read either. The
expressions are `PropertyPath`s. A control no binder supports binds nothing, as upstream's
run-time path does (the generated code throws when it finds no event at compile time).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L253)

## Members

- [`bind_command`](#function-bind_command)
- [`bind_command_with_parameter`](#function-bind_command_with_parameter)
- [`bind_command_with_parameter_path`](#function-bind_command_with_parameter_path)
- [`bind_command_on`](#function-bind_command_on)
- [`bind_command_with_parameter_on`](#function-bind_command_with_parameter_on)
- [`bind_command_with_parameter_path_on`](#function-bind_command_with_parameter_path_on)

<a id="function-bind_command"></a>

### bind_command

```rust
fn bind_command<VM, X, CV>(self: &Self, command: PropertyPath<Rc<VM>, X>, control: PropertyPath<Rc<V>, CV>, to_event: Option<ToEvent<<CV as >::Control>>) -> Rc<dyn IDisposable>
where V: IViewForOf<VM>,
      VM: 'static,
      X: CommandValue,
      CV: ControlValue
```

Binds the command `command` reads from the view's view model to the control `control` reads
from the view (`BindCommand(viewModel, propertyName, controlName, toEvent)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L256)

<a id="function-bind_command_with_parameter"></a>

### bind_command_with_parameter

```rust
fn bind_command_with_parameter<VM, X, CV, P>(self: &Self, command: PropertyPath<Rc<VM>, X>, control: PropertyPath<Rc<V>, CV>, parameter: Rc<dyn IObservable<P>>, to_event: Option<ToEvent<<CV as >::Control>>) -> Rc<dyn IDisposable>
where V: IViewForOf<VM>,
      VM: 'static,
      X: CommandValue,
      CV: ControlValue,
      P: 'static
```

`bind_command` with the values of `parameter` as the command
parameter (`BindCommand(..., IObservable<TParam?> withParameter, toEvent)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L265)

<a id="function-bind_command_with_parameter_path"></a>

### bind_command_with_parameter_path

```rust
fn bind_command_with_parameter_path<VM, X, CV, P>(self: &Self, command: PropertyPath<Rc<VM>, X>, control: PropertyPath<Rc<V>, CV>, parameter: PropertyPath<Rc<VM>, P>, to_event: Option<ToEvent<<CV as >::Control>>) -> Rc<dyn IDisposable>
where V: IViewForOf<VM>,
      VM: 'static,
      X: CommandValue,
      CV: ControlValue,
      P: Clone + PartialEq + 'static
```

`bind_command` with the property `parameter` of the view's view model
as the command parameter, observed so that the control sees each of its values
(`BindCommand(..., Expression<Func<TViewModel, TParam?>> withParameter, toEvent)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L282)

<a id="function-bind_command_on"></a>

### bind_command_on

```rust
fn bind_command_on<VM, X, CV>(self: &Self, view_model: Option<Rc<VM>>, command: PropertyPath<Rc<VM>, X>, control: PropertyPath<Rc<V>, CV>, to_event: Option<ToEvent<<CV as >::Control>>) -> Rc<dyn IDisposable>
where VM: 'static,
      X: CommandValue,
      CV: ControlValue
```

`bind_command` rooted at `view_model`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L297)

<a id="function-bind_command_with_parameter_on"></a>

### bind_command_with_parameter_on

```rust
fn bind_command_with_parameter_on<VM, X, CV, P>(self: &Self, view_model: Option<Rc<VM>>, command: PropertyPath<Rc<VM>, X>, control: PropertyPath<Rc<V>, CV>, parameter: Rc<dyn IObservable<P>>, to_event: Option<ToEvent<<CV as >::Control>>) -> Rc<dyn IDisposable>
where VM: 'static,
      X: CommandValue,
      CV: ControlValue,
      P: 'static
```

`bind_command_with_parameter` rooted at `view_model`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L310)

<a id="function-bind_command_with_parameter_path_on"></a>

### bind_command_with_parameter_path_on

```rust
fn bind_command_with_parameter_path_on<VM, X, CV, P>(self: &Self, view_model: Option<Rc<VM>>, command: PropertyPath<Rc<VM>, X>, control: PropertyPath<Rc<V>, CV>, parameter: PropertyPath<Rc<VM>, P>, to_event: Option<ToEvent<<CV as >::Control>>) -> Rc<dyn IDisposable>
where VM: 'static,
      X: CommandValue,
      CV: ControlValue,
      P: Clone + PartialEq + 'static
```

`bind_command_with_parameter_path` rooted at
`view_model`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/mixins/reactive_ui_binding_extensions_bind_command.rs#L326)

## Trait implementations

- [`BindCommandMixins<V>`](/docs/0.5.0/api/ferroui-reactiveui/binding/mixins/trait-bindcommandmixins/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
