Skip to content

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

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

Defined in

Type: ICreatesCommandBinding Namespace: ReactiveUI.Binding Assembly: ReactiveUI.Binding.dll

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481

Overloads

  • 1. IDisposable? BindCommandToObject<T>(ICommand? command, T? target, IObservable<object?> commandParameter) where T : class
  • 2. IDisposable? BindCommandToObject<T, TEventArgs>(ICommand? command, T? target, IObservable<object?> commandParameter, string eventName) where T : class
  • 3. 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.")]

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

Summary: Binds an ICommand to a UI object using the default event. The default event is determined by the implementation (e.g., Click, TouchUpInside).

Type parameters

NameDescription
TThe type of the target object.

Parameters

NameTypeDescription
commandICommand?The command to bind. If null, no binding is created.
targetT?The target object, usually a UI control.
commandParameterIObservableAn observable that provides the command parameter value.

Returns: IDisposable? -- An IDisposable that disconnects the binding when disposed, or null if no binding was created.

2. Overload

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

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

Summary: Binds an ICommand to a UI object to a specific named event.

Type parameters

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

Parameters

NameTypeDescription
commandICommand?The command to bind. If null, no binding is created.
targetT?The target object, usually a UI control.
commandParameterIObservableAn observable that provides the command parameter value.
eventNamestringThe event to bind to.

Returns: IDisposable? -- An IDisposable that disconnects the binding when disposed, or null if no binding was created.

3. Overload

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

Summary: Binds a command to a specific event on a target object using explicit add/remove handler delegates. This overload is fully AOT-compatible as it avoids reflection-based event lookup.

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.