Skip to content

)} ,System.String)} ,System.Action{System.EventHandler{--1}},System.Action{System.EventHandler{--1}})}

CreatesCommandBindingViaCommandParameter.BindCommandToObject(ICommand?, T?, IObservable) method

Defined in

Type: CreatesCommandBindingViaCommandParameter Namespace: ReactiveUI Assembly: ReactiveUI.Core.dll

Applies to

net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471

Overloads

  • 1. public IDisposable? BindCommandToObject<T>(ICommand? command, T? target, IObservable<object?> commandParameter) where T : class
  • 2. public IDisposable? BindCommandToObject<T, TEventArgs>(ICommand? command, T? target, IObservable<object?> commandParameter, string eventName) where T : class
  • 3. public IDisposable? BindCommandToObject<T, TEventArgs>(ICommand? command, T? target, IObservable<object?> commandParameter, Action<EventHandler<TEventArgs>> addHandler, Action<EventHandler<TEventArgs>> removeHandler) where T : class where TEventArgs : EventArgs

1. Overload

Attributes: [RequiresUnreferencedCode("String/reflection-based event binding may require members removed by trimming.")]

public IDisposable? BindCommandToObject<T>(ICommand? command, T? target, IObservable<object?> commandParameter) where T : class

View source

Inherited documentation

These docs were inherited from ICreatesCommandBinding. The member doesn't override them on this type.

Summary: Bind an ICommand to a UI object, in the "default" way. The meaning of this is dependent on the implementation. This method will discover which event to bind to (e.g., Click, MouseUp) based on the control type. Implement this if you have a new type of UI control that doesn't have Command/CommandParameter like WPF or has a non-standard event name for "Invoke".

Type parameters

NameDescription
TThe type of the target object to which the command is bound. Must be a reference type.

Parameters

NameTypeDescription
commandICommand?The command to bind. Can be null.
targetT?The target object, usually a UI control of some kind. Can be null.
commandParameterIObservableAn IObservable source whose latest value will be passed as the command parameter to the command. Hosts will always pass a valid IObservable, but this may be Observable.Empty.

Returns: IDisposable? -- An IDisposable which will disconnect the binding when disposed, or null if no binding was created.

Remarks

This implementation is intentionally “best effort.” If required properties cannot be resolved for T, it returns EmptyDisposable to preserve legacy behavior where binder selection is expected to be affinity-driven rather than exception-driven.

Disposal ordering minimizes observable races: the parameter subscription is disposed before restoring the original parameter value.

The command property is set after establishing the parameter subscription, preserving historical ordering semantics (“set Command last”).

2. Overload

Attributes: [RequiresUnreferencedCode("String/reflection-based event binding may require members removed by trimming.")]

public IDisposable? BindCommandToObject<T, TEventArgs>(ICommand? command, T? target, IObservable<object?> commandParameter, string eventName) where T : class

View source

Inherited documentation

These docs were inherited from ICreatesCommandBinding. The member doesn't override them on this type.

Summary: Bind an ICommand to a UI object to a specific event. This event may be a standard .NET event, or it could be an event derived in another manner (i.e. in MonoTouch). This method is fully AOT-compatible as it uses generic type parameters instead of reflection.

Type parameters

NameDescription
TThe type of the target object to which the command is bound. Must be a reference type.
TEventArgsThe event argument type.

Parameters

NameTypeDescription
commandICommand?The command to bind. Can be null.
targetT?The target object, usually a UI control of some kind. Can be null.
commandParameterIObservableAn IObservable source whose latest value will be passed as the command parameter to the command. Hosts will always pass a valid IObservable, but this may be Observable.Empty.
eventNamestringThe event to bind to.

Returns: IDisposable? -- An IDisposable which will disconnect the binding when disposed, or null if no binding was created.

Remarks

This binder is for command-property based binding. If an event name is specified, event-based binders should be used. This method therefore returns EmptyDisposable.

3. Overload

public IDisposable? BindCommandToObject<T, TEventArgs>(ICommand? command, T? target, IObservable<object?> commandParameter, Action<EventHandler<TEventArgs>> addHandler, Action<EventHandler<TEventArgs>> removeHandler) where T : class where TEventArgs : EventArgs

View source

Inherited documentation

These docs were inherited from ICreatesCommandBinding. The member doesn't override them on this type.

Summary: Binds a command to a specific event on a target object using explicit add/remove handler delegates.

Type parameters

NameDescription
TThe type of the target object.
TEventArgsThe event arguments type.

Parameters

NameTypeDescription
commandICommand?The command to bind. If null, no binding is created.
targetT?The target object.
commandParameterIObservableAn observable that supplies command parameter values.
addHandlerAction>Adds the handler to the target event.
removeHandlerAction>Removes the handler from the target event.

Returns: IDisposable? -- A disposable that unbinds the command.

Remarks

This binder is for command-property based binding. If an event name is specified, event-based binders should be used. This method therefore returns EmptyDisposable.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when target, addHandler, or removeHandler is null.