Table of Contents

Class ObservableAsPropertyHelper<T>

Namespace
ReactiveUI
Assembly
ReactiveUI.dll

ObservableAsPropertyHelper is a class to help ViewModels implement "output properties", that is, a property that is backed by an Observable. The property will be read-only, but will still fire change notifications. This class can be created directly, but is more often created via the OAPHCreationHelperMixin extension methods.

public sealed class ObservableAsPropertyHelper<T> : Object, IHandleObservableErrors, IDisposable, IEnableLogger

Type Parameters

T

The type.

Inheritance
ObservableAsPropertyHelper<T>
Implements
Extension Methods
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)

Constructors

ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, Action<T?>?, Func<T?>?, bool, IScheduler?)

Initializes a new instance of the ObservableAsPropertyHelper<T> class.

public ObservableAsPropertyHelper(IObservable<T?> observable, Action<T?> onChanged, Action<T?>? onChanging = null, Func<T?>? getInitialValue = null, bool deferSubscription = false, IScheduler? scheduler = null)

Parameters

observable IObservable<T>

The Observable to base the property on.

onChanged Action<T>

The action to take when the property changes, typically this will call the ViewModel's RaisePropertyChanged method.

onChanging Action<T>

The action to take when the property changes, typically this will call the ViewModel's RaisePropertyChanging method.

getInitialValue Func<T>

The function used to retrieve the initial value of the property.

deferSubscription bool

A value indicating whether the ObservableAsPropertyHelper<T> should defer the subscription to the observable source until the first call to Value, or if it should immediately subscribe to the observable source.

scheduler IScheduler

The scheduler that the notifications will provided on - this should normally be a Dispatcher-based scheduler.

ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, Action<T?>?, T?, bool, IScheduler?)

Initializes a new instance of the ObservableAsPropertyHelper<T> class.

public ObservableAsPropertyHelper(IObservable<T?> observable, Action<T?> onChanged, Action<T?>? onChanging = null, T? initialValue = default, bool deferSubscription = false, IScheduler? scheduler = null)

Parameters

observable IObservable<T>

The Observable to base the property on.

onChanged Action<T>

The action to take when the property changes, typically this will call the ViewModel's RaisePropertyChanged method.

onChanging Action<T>

The action to take when the property changes, typically this will call the ViewModel's RaisePropertyChanging method.

initialValue T

The initial value of the property.

deferSubscription bool

A value indicating whether the ObservableAsPropertyHelper<T> should defer the subscription to the observable source until the first call to Value, or if it should immediately subscribe to the observable source.

scheduler IScheduler

The scheduler that the notifications will provided on - this should normally be a Dispatcher-based scheduler.

ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, T?, bool, IScheduler?)

Initializes a new instance of the ObservableAsPropertyHelper<T> class.

public ObservableAsPropertyHelper(IObservable<T?> observable, Action<T?> onChanged, T? initialValue = default, bool deferSubscription = false, IScheduler? scheduler = null)

Parameters

observable IObservable<T>

The Observable to base the property on.

onChanged Action<T>

The action to take when the property changes, typically this will call the ViewModel's RaisePropertyChanged method.

initialValue T

The initial value of the property.

deferSubscription bool

A value indicating whether the ObservableAsPropertyHelper<T> should defer the subscription to the observable source until the first call to Value, or if it should immediately subscribe to the observable source.

scheduler IScheduler

The scheduler that the notifications will be provided on - this should normally be a Dispatcher-based scheduler.

Properties

IsSubscribed

Gets a value indicating whether the ObservableAsPropertyHelper has subscribed to the source Observable. Useful for scenarios where you use deferred subscription and want to know if the ObservableAsPropertyHelper Value has been accessed yet.

public bool IsSubscribed { get; }

Property Value

bool

ThrownExceptions

Gets an observable which signals whenever an exception would normally terminate ReactiveUI internal state.

public IObservable<Exception> ThrownExceptions { get; }

Property Value

IObservable<Exception>

Value

Gets the last provided value from the Observable.

public T Value { get; }

Property Value

T

Methods

Default(T?, IScheduler?)

Constructs a "default" ObservableAsPropertyHelper object. This is useful for when you will initialize the OAPH later, but don't want bindings to access a null OAPH at start up.

public static ObservableAsPropertyHelper<T> Default(T? initialValue = default, IScheduler? scheduler = null)

Parameters

initialValue T

The initial (and only) value of the property.

scheduler IScheduler

The scheduler that the notifications will be provided on - this should normally be a Dispatcher-based scheduler.

Returns

ObservableAsPropertyHelper<T>

A default property helper.

Dispose()

Disposes this ObservableAsPropertyHelper.

public void Dispose()