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
impl CommandCanExecuteObserver
Sourcepub fn new(set_can_execute: impl Fn(bool) + 'static) -> Self
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.
Sourcepub fn start(
&self,
command: Option<Rc<dyn ICommand>>,
parameter: Option<BoxedValue>,
)
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.
Sourcepub fn start_with(
&self,
command: Option<Rc<dyn ICommand>>,
parameter: Option<BoxedValue>,
is_parameter_known: bool,
)
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.
Sourcepub fn update(
&self,
command: Option<Rc<dyn ICommand>>,
parameter: Option<BoxedValue>,
)
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.
Sourcepub fn update_with(
&self,
command: Option<Rc<dyn ICommand>>,
parameter: Option<BoxedValue>,
is_parameter_known: bool,
)
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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for CommandCanExecuteObserver
impl !Send for CommandCanExecuteObserver
impl !Sync for CommandCanExecuteObserver
impl !UnwindSafe for CommandCanExecuteObserver
impl Freeze for CommandCanExecuteObserver
impl Unpin for CommandCanExecuteObserver
impl UnsafeUnpin for CommandCanExecuteObserver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more