# ICreatesCommandBinding

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

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

```rust
trait ICreatesCommandBinding
```

A plugin that binds an [`ICommand`](/docs/0.5.0/api/ferroui-reactiveui/reactive_command/trait-icommand/) to a control (`ICreatesCommandBinding`). The
implementations are registered in the service locator (Splat) as `dyn ICreatesCommandBinding`,
and the one with the highest affinity for the type of a control binds it
(`CommandBinderService`), as upstream.

The crate registers none: `CreatesCommandBindingViaEvent`
and `CreatesCommandBindingViaCommandParameter`
bind the controls of one type, and a platform registers its own (the controls of FerroUI).

Deviation (DEVIATIONS.md, ReactiveUI): the trait is object safe. The type parameter `T` of the
control is a `TypeId` in `get_affinity_for_object` and the
control an `Rc<dyn Any>` in the bindings; `TEventArgs` has no counterpart (the handler ignores
the arguments of the event); the add and remove handlers are one
[`CommandEventSubscription`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/type_alias-commandeventsubscription/); the command parameter is an observable of [`CommandParameter`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/type_alias-commandparameter/).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_creates_command_binding.rs#L30)

## Members

- [`get_affinity_for_object`](#function-get_affinity_for_object)
- [`bind_command_to_object`](#function-bind_command_to_object)
- [`bind_command_to_object_event`](#function-bind_command_to_object_event)
- [`bind_command_to_object_with_handlers`](#function-bind_command_to_object_with_handlers)

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

### get_affinity_for_object

```rust
fn get_affinity_for_object(self: &Self, target_type: TypeId, has_event_target: bool) -> i32
```

A positive number when this plugin can bind a command to an object of the type
`target_type`, the highest number winning among the plugins; zero or less when it cannot
(`GetAffinityForObject<T>(bool hasEventTarget)`). `has_event_target` says whether the caller
names the event to bind to.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_creates_command_binding.rs#L35)

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

### bind_command_to_object

```rust
fn bind_command_to_object(self: &Self, command: Option<Rc<dyn ICommand>>, target: Option<Rc<dyn Any>>, command_parameter: Rc<dyn IObservable<CommandParameter>>) -> Option<Rc<dyn IDisposable>>
```

Binds `command` to `target` through the default event of the target (`Click`, ...), executed
with the latest value of `command_parameter`; `None` when no binding was made, as for a
missing command (`BindCommandToObject<T>`). Disposing the result unbinds the command.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_creates_command_binding.rs#L40)

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

### bind_command_to_object_event

```rust
fn bind_command_to_object_event(self: &Self, command: Option<Rc<dyn ICommand>>, target: Option<Rc<dyn Any>>, command_parameter: Rc<dyn IObservable<CommandParameter>>, event_name: &str) -> Option<Rc<dyn IDisposable>>
```

Binds `command` to the event named `event_name` of `target`
(`BindCommandToObject<T, TEventArgs>(..., string eventName)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_creates_command_binding.rs#L49)

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

### bind_command_to_object_with_handlers

```rust
fn bind_command_to_object_with_handlers(self: &Self, command: Option<Rc<dyn ICommand>>, target: Option<Rc<dyn Any>>, command_parameter: Rc<dyn IObservable<CommandParameter>>, subscription: CommandEventSubscription) -> Option<Rc<dyn IDisposable>>
```

Binds `command` to the event that `subscription` adds a handler to
(`BindCommandToObject<T, TEventArgs>(..., addHandler, removeHandler)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_creates_command_binding.rs#L59)

## Trait implementations

- [`ICreatesCommandBinding`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/trait-icreatescommandbinding/)

## Availability

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