Skip to content

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

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

Defined in

Type: TargetActionCommandBinder Namespace: ReactiveUI.Reactive Assembly: ReactiveUI.Reactive.dll

Applies to

net10.0-ios26.0, net10.0-macos26.0, net10.0-maccatalyst26.0, net10.0-tvos26.0

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 target type being bound.

Parameters

NameTypeDescription
commandICommand?The command to bind to the target.
targetT?The target object to bind the command to.
commandParameterIObservableAn observable providing the latest command parameter.

Returns: IDisposable? -- A disposable that tears down the binding, or null when binding is not possible.

Remarks

This binds via Target/Action, not via a .NET event. It requires that the runtime type exposes a Target property and that a selector named theAction: can be invoked on the target.

If the runtime type also exposes an Enabled property, it is synchronized with CanExecute and CanExecuteChanged.

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 target type being bound.
TEventArgsThe event args type of the named event.

Parameters

NameTypeDescription
commandICommand?The command to bind to the target.
targetT?The target object to bind the command to.
commandParameterIObservableAn observable providing the latest command parameter.
eventNamestringThe name of the event to subscribe to.

Returns: IDisposable? -- A disposable that tears down the binding, or null when binding is not possible.

Remarks

        This overload binds to a named .NET event. It is reflection-based and therefore not trimming-safe.
        Prefer the add/remove handler overload when you can supply delegates.
        

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 target type being bound.
TEventArgsThe event args type of the subscribed event.

Parameters

NameTypeDescription
commandICommand?The command to bind to the target.
targetT?The target object to bind the command to.
commandParameterIObservableAn observable providing the latest command parameter.
addHandlerAction>Adds the event handler to the target.
removeHandlerAction>Removes the event handler from the target.

Returns: IDisposable? -- A disposable that tears down the binding, or null when binding is not possible.

Remarks

        This overload is fully AOT-compatible and should be preferred when an explicit event subscription API is available.
        

Exceptions

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