Exemplo n.º 1
0
        /// <summary>
        /// Adds a binding.
        /// </summary>
        /// <param name="binding">The binding to add.</param>
        /// <returns>A disposable used to remove the binding.</returns>
        public IDisposable Add(IObservable <object> binding)
        {
            Contract.Requires <ArgumentNullException>(binding != null);

            var entry = new PriorityBindingEntry(_nextIndex++);
            var node  = Bindings.AddFirst(entry);

            entry.Start(binding, Changed, Completed);

            return(Disposable.Create(() =>
            {
                Bindings.Remove(node);
                entry.Dispose();

                if (entry.Index >= ActiveBindingIndex)
                {
                    ActivateFirstBinding();
                }
            }));
        }