Skip to content

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

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

Defined in

Type: CreatesCommandBindingViaEvent Namespace: ReactiveUI Assembly: ReactiveUI.dll

Applies to

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

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
  • 4. public IDisposable BindCommandToObject<T>(ICommand? command, T? target, IObservable<object?> commandParameter, Action<EventHandler> addHandler, Action<EventHandler> removeHandler) where T : class

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

Summary: Binds a command to the default event on a target object using a generic type parameter.

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.
commandParameterIObservableAn observable that supplies command parameter values.

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

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when target is null.
System.ExceptionThrown when no default event exists on T and the caller did not specify an event explicitly.

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

Summary: Binds a command to a specific event on a target object using generic type parameters.

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.
eventNamestringThe name of the event to bind to.

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

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when target or eventName is null.
System.ArgumentExceptionThrown when eventName is empty.

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

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.

Exceptions

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

4. Overload

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

View source

Summary: Binds a command to an event using explicit add/remove handler actions (non-reflection).

Type parameters

NameDescription
TThe target 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.
addHandlerActionAdds the handler to the target event.
removeHandlerActionRemoves the handler from the target event.

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

Exceptions

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