// ----------------------------------------------------------------------- // // Copyright 2013 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Styling { using System; using System.Reactive; /// /// Provides an observable for a style. /// /// /// This class takes an activator and a value. The activator is an observable which produces /// a bool. When the activator produces true, this observable will produce . /// When the activator produces false it will produce . /// internal class StyleBinding : ObservableBase, IDescription { /// /// The activator. /// private IObservable activator; /// /// Initializes a new instance of the class. /// /// The activator. /// The activated value. /// The binding description. public StyleBinding( IObservable activator, object activatedValue, string description) { this.activator = activator; this.ActivatedValue = activatedValue; this.Description = description; } /// /// Gets a description of the binding. /// public string Description { get; private set; } /// /// Gets the activated value. /// public object ActivatedValue { get; private set; } /// /// Notifies the provider that an observer is to receive notifications. /// /// The observer. /// IDisposable object used to unsubscribe from the observable sequence. protected override IDisposable SubscribeCore(IObserver observer) { Contract.Requires(observer != null); return this.activator.Subscribe( active => observer.OnNext(active ? this.ActivatedValue : PerspexProperty.UnsetValue), observer.OnError, observer.OnCompleted); } } }