Class PropertyBinderImplementation
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
Provides methods to bind properties to observables.
- Inheritance
-
Property
Binder Implementation
- Implements
- Extension Methods
Constructors
PropertyBinderImplementation()
Methods
BindTo<TValue, TTarget, TTValue>(IObservable<TValue>, TTarget?, Expression<Func<TTarget, TTValue?>>, object?, IBindingTypeConverter?)
BindTo takes an Observable stream and applies it to a target property. Conceptually it is similar to.
Subscribe(x =>
target.property = x)
, but allows you to use child properties
without the null checks.
public IDisposable BindTo<TValue, TTarget, TTValue>(IObservable<TValue> observedChange, TTarget? target, Expression<Func<TTarget, TTValue?>> propertyExpression, object? conversionHint = null, IBindingTypeConverter? vmToViewConverterOverride = null) where TTarget : class
Parameters
observedChange
IObservable<TValue>The target observable to bind to.
target
TTargetThe target object whose property will be set.
propertyExpression
Expression<Func<TTarget, TTValue>>An expression representing the target property to set. This can be a child property (i.e.
x.Foo.Bar.Baz
).conversionHint
objectAn object that can provide a hint for the converter. The semantics of this object is defined by the converter used.
vmToViewConverterOverride
IBindingType Converter An optional IBinding
Type to use when converting from the viewModel to view property.Converter
Returns
- IDisposable
An object that when disposed, disconnects the binding.
Type Parameters
TValue
The value type.
TTarget
The target type.
TTValue
The target value type.
Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(TViewModel?, TView, Expression<Func<TViewModel, TVMProp?>>, Expression<Func<TView, TVProp>>, IObservable<TDontCare>?, Func<TVMProp?, TVProp>, Func<TVProp, TVMProp?>, TriggerUpdate)
Creates a two-way binding between a view model and a view.
This binding will attempt to convert the values of the
view and view model properties using a IBinding
public IReactiveBinding<TView, (object? view, bool isViewModel)> Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TVMProp?>> vmProperty, Expression<Func<TView, TVProp>> viewProperty, IObservable<TDontCare>? signalViewUpdate, Func<TVMProp?, TVProp> vmToViewConverter, Func<TVProp, TVMProp?> viewToVmConverter, TriggerUpdate triggerUpdate = TriggerUpdate.ViewToViewModel) where TViewModel : class where TView : class, IViewFor
Parameters
viewModel
TViewModel The instance of the view model object to be bound.
view
TViewThe instance of the view object to be bound.
vmProperty
Expression<Func<TViewModel, TVMProp>>An expression representing the property to be bound to on the view model. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always get and set the correct property.viewProperty
Expression<Func<TView, TVProp>>An expression representing the property to be bound to on the view. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always get and set the correct property.signalViewUpdate
IObservable<TDontCare>An observable, that when signaled, indicates that the view property has been changed, and that the binding should update the view model property accordingly.
vmToViewConverter
Func<TVMProp, TVProp>Delegate to convert the value of the view model's property's type to a value of the view's property's type.
viewToVmConverter
Func<TVProp, TVMProp>Delegate to convert the value of the view's property's type to a value of the view model's property's type.
triggerUpdate
TriggerUpdate The trigger update direction.
Returns
- IReactive
Binding <TView, (object view, bool isView )>Model An instance of IDisposable that, when disposed, disconnects the binding.
Type Parameters
TViewModel
The type of the view model that is bound.
TView
The type of the view being bound.
TVMProp
The type of the property bound on the view model.
TVProp
The type of the property bound on the view.
TDontCare
A dummy type, only the fact that
signalViewUpdate
emits values is considered, not the actual values emitted.
Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(TViewModel?, TView, Expression<Func<TViewModel, TVMProp?>>, Expression<Func<TView, TVProp>>, IObservable<TDontCare>?, object?, IBindingTypeConverter?, IBindingTypeConverter?, TriggerUpdate)
Creates a two-way binding between a view model and a view.
This binding will attempt to convert the values of the
view and view model properties using a IBinding
public IReactiveBinding<TView, (object? view, bool isViewModel)> Bind<TViewModel, TView, TVMProp, TVProp, TDontCare>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TVMProp?>> vmProperty, Expression<Func<TView, TVProp>> viewProperty, IObservable<TDontCare>? signalViewUpdate, object? conversionHint, IBindingTypeConverter? vmToViewConverterOverride = null, IBindingTypeConverter? viewToVMConverterOverride = null, TriggerUpdate triggerUpdate = TriggerUpdate.ViewToViewModel) where TViewModel : class where TView : class, IViewFor
Parameters
viewModel
TViewModel The instance of the view model object to be bound.
view
TViewThe instance of the view object to be bound.
vmProperty
Expression<Func<TViewModel, TVMProp>>An expression representing the property to be bound to on the view model. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always get and set the correct property.viewProperty
Expression<Func<TView, TVProp>>An expression representing the property to be bound to on the view. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always get and set the correct property.signalViewUpdate
IObservable<TDontCare>An observable, that when signaled, indicates that the view property has been changed, and that the binding should update the view model property accordingly.
conversionHint
objectAn object that can provide a hint for the converter. The semantics of this object is defined by the converter used.
vmToViewConverterOverride
IBindingType Converter An optional IBinding
Type to use when converting from the viewModel to view property.Converter viewToVMConverterOverride
IBindingType Converter An optional IBinding
Type to use when converting from the view to viewModel property.Converter triggerUpdate
TriggerUpdate The trigger update direction.
Returns
- IReactive
Binding <TView, (object view, bool isView )>Model An instance of IDisposable that, when disposed, disconnects the binding.
Type Parameters
TViewModel
The type of the view model that is bound.
TView
The type of the view being bound.
TVMProp
The type of the property bound on the view model.
TVProp
The type of the property bound on the view.
TDontCare
A dummy type, only the fact that
signalViewUpdate
emits values is considered, not the actual values emitted.
OneWayBind<TViewModel, TView, TProp, TOut>(TViewModel?, TView, Expression<Func<TViewModel, TProp?>>, Expression<Func<TView, TOut>>, Func<TProp, TOut>)
Creates a one way binding with a selector, i.e. a binding that flows from the
viewModel
to the view
only, and where the value of the view model
property is mapped through the selector
before being set to the view.
public IReactiveBinding<TView, TOut> OneWayBind<TViewModel, TView, TProp, TOut>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TProp?>> vmProperty, Expression<Func<TView, TOut>> viewProperty, Func<TProp, TOut> selector) where TViewModel : class where TView : class, IViewFor
Parameters
viewModel
TViewModel The instance of the view model to bind to.
view
TViewThe instance of the view to bind to.
vmProperty
Expression<Func<TViewModel, TProp>>An expression representing the property to be bound to on the view model. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always get the last value of the property chain.viewProperty
Expression<Func<TView, TOut>>An expression representing the property to be bound to on the view. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always set the correct property.selector
Func<TProp, TOut>A function that will be used to transform the values of the property on the view model before being bound to the view property.
Returns
- IReactive
Binding <TView, TOut> An instance of IDisposable that, when disposed, disconnects the binding.
Type Parameters
TViewModel
The type of the view model that is bound.
TView
The type of the view that is bound.
TProp
The type of the property bound on the view model.
TOut
The return type of the
selector
.
OneWayBind<TViewModel, TView, TVMProp, TVProp>(TViewModel?, TView, Expression<Func<TViewModel, TVMProp?>>, Expression<Func<TView, TVProp>>, object?, IBindingTypeConverter?)
Creates a one-way binding, i.e. a binding that flows from the
viewModel
to the view
only. This binding will
attempt to convert the value of the view model property to the view property if they
are not of the same type.
public IReactiveBinding<TView, TVProp> OneWayBind<TViewModel, TView, TVMProp, TVProp>(TViewModel? viewModel, TView view, Expression<Func<TViewModel, TVMProp?>> vmProperty, Expression<Func<TView, TVProp>> viewProperty, object? conversionHint = null, IBindingTypeConverter? vmToViewConverterOverride = null) where TViewModel : class where TView : class, IViewFor
Parameters
viewModel
TViewModel The instance of the view model to bind to.
view
TViewThe instance of the view to bind to.
vmProperty
Expression<Func<TViewModel, TVMProp>>An expression representing the property to be bound to on the view model. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always get the last value of the property chain.viewProperty
Expression<Func<TView, TVProp>>An expression representing the property to be bound to on the view. This can be a child property, for example
x => x.Foo.Bar.Baz
in which case the binding will attempt to subscribe recursively to updates in order to always set the correct property.conversionHint
objectAn object that can provide a hint for the converter. The semantics of this object is defined by the converter used.
vmToViewConverterOverride
IBindingType Converter An optional IBinding
Type to use when converting from the viewModel to view property.Converter
Returns
- IReactive
Binding <TView, TVProp> An instance of IDisposable that, when disposed, disconnects the binding.
Type Parameters
TViewModel
The type of the view model that is bound.
TView
The type of the view that is bound.
TVMProp
The type of the property bound on the view model.
TVProp
The type of the property bound on the view.
Exceptions
- Argument
Exception There is no registered converter from
TVMProp
toTVProp
.