Skip to main content

CommandCanExecuteObserver

Struct CommandCanExecuteObserver 

Source
pub struct CommandCanExecuteObserver { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl CommandCanExecuteObserver

Source

pub 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

pub fn start( &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

pub fn start_with( &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

pub fn update( &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

pub fn update_with( &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

pub fn stop(&self)

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

Trait Implementations§

Source§

impl IDisposable for CommandCanExecuteObserver

Source§

fn dispose(&self)

Stops observing the current command.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.