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 OAPHCreation
public sealed class ObservableAsPropertyHelper<T> : IHandleObservableErrors, IDisposable, IEnableLogger
Type Parameters
T
The type.
- Inheritance
-
ObservableAsPropertyHelper<T>
- Implements
- Extension Methods
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
boolA 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 theobservable
source.scheduler
ISchedulerThe 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
TThe initial value of the property.
deferSubscription
boolA 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 theobservable
source.scheduler
ISchedulerThe 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
TThe initial value of the property.
deferSubscription
boolA 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 theobservable
source.scheduler
ISchedulerThe 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.
Property Value
ThrownExceptions
Gets an observable which signals whenever an exception would normally terminate ReactiveUI internal state.
Property Value
Value
Gets the last provided value from the Observable.
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
TThe initial (and only) value of the property.
scheduler
ISchedulerThe scheduler that the notifications will be provided on - this should normally be a Dispatcher-based scheduler.
Returns
- Observable
AsProperty <T>Helper A default property helper.
Dispose()
Disposes this ObservableAsPropertyHelper.