# CommandCanExecuteObserver

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-xaml-interactivity/helpers/struct-commandcanexecuteobserver/

**struct** · [`ferroui-xaml-interactivity`](/docs/0.5.0/api/ferroui-xaml-interactivity/) · v0.5.0

```rust
struct CommandCanExecuteObserver
```

Observes an `ICommand` and reports whether it can execute with a specified parameter.

Use this helper from custom command-backed behaviors to expose a bindable command state, such
as a direct property. Call `start` when the behavior is attached,
`update` when the command or command parameter changes, and
`stop` when the behavior is detached.

The command event subscription uses a weak reference to this observer so a long-lived command
does not keep the observer or owning behavior alive if cleanup is missed.

Deviation (DEVIATIONS.md, Behaviors): the reference posts the callback to the user-interface
thread when a command raises its notification on another thread. Commands and observers of
the port belong to the thread that created them (they are not `Send`), so the callback always
runs on that thread.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L23)

## Members

- [`new`](#function-new)
- [`start`](#function-start)
- [`start_with`](#function-start_with)
- [`update`](#function-update)
- [`update_with`](#function-update_with)
- [`stop`](#function-stop)

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

### new

```rust
fn new(set_can_execute: impl Fn(bool) -> () + 'static) -> Self
```

Initializes a new instance of the `CommandCanExecuteObserver` class; `set_can_execute`
receives the current command execution state.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L39)

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

### start

```rust
fn start(self: &Self, command: Option<Rc<dyn ICommand>>, parameter: Option<BoxedValue>)
```

Starts observing the specified command and reports its initial execution state; a null
command reports that execution is allowed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L53)

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

### start_with

```rust
fn start_with(self: &Self, command: Option<Rc<dyn ICommand>>, parameter: Option<BoxedValue>, is_parameter_known: bool)
```

Starts observing the specified command and reports its initial execution state.

`is_parameter_known` is true when `parameter` is the actual parameter to evaluate, false
when the parameter will only be available at execution time: the observer then reports
true without calling `can_execute`, which avoids probing commands with placeholder values
such as null when event arguments or picker results will provide the real parameter later.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L63)

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

### update

```rust
fn update(self: &Self, command: Option<Rc<dyn ICommand>>, parameter: Option<BoxedValue>)
```

Updates the observed command and command parameter. Has no effect until
`start` has been called.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L84)

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

### update_with

```rust
fn update_with(self: &Self, command: Option<Rc<dyn ICommand>>, parameter: Option<BoxedValue>, is_parameter_known: bool)
```

Updates the observed command and command parameter; see `start_with`
for `is_parameter_known`. Has no effect until `start` has been called.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L90)

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

### stop

```rust
fn stop(self: &Self)
```

Stops observing the current command and clears the stored command parameter.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/Behaviors/FerroUI.Xaml.Interactivity/helpers/command_can_execute_observer.rs#L117)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)

## Availability

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