Ejemplo n.º 1
0
        /// <summary>
        /// Binds a <see cref="AvaloniaProperty"/> to an observable.
        /// </summary>
        /// <typeparam name="T">The type of the property.</typeparam>
        /// <param name="property">The property.</param>
        /// <param name="source">The observable.</param>
        /// <param name="priority">The priority of the binding.</param>
        /// <returns>
        /// A disposable which can be used to terminate the binding.
        /// </returns>
        public IDisposable Bind <T>(
            StyledPropertyBase <T> property,
            IObservable <BindingValue <T> > source,
            BindingPriority priority = BindingPriority.LocalValue)
        {
            property = property ?? throw new ArgumentNullException(nameof(property));
            source   = source ?? throw new ArgumentNullException(nameof(source));
            VerifyAccess();

            return(Values.AddBinding(property, source, priority));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Binds a <see cref="AvaloniaProperty"/> to an observable.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="source">The observable.</param>
        /// <param name="priority">The priority of the binding.</param>
        /// <returns>
        /// A disposable which can be used to terminate the binding.
        /// </returns>
        public IDisposable Bind(
            AvaloniaProperty property,
            IObservable <object> source,
            BindingPriority priority = BindingPriority.LocalValue)
        {
            Contract.Requires <ArgumentNullException>(property != null);
            Contract.Requires <ArgumentNullException>(source != null);

            VerifyAccess();

            var description = GetDescription(source);

            if (property.IsDirect)
            {
                if (property.IsReadOnly)
                {
                    throw new ArgumentException($"The property {property.Name} is readonly.");
                }

                Logger.Verbose(
                    LogArea.Property,
                    this,
                    "Bound {Property} to {Binding} with priority LocalValue",
                    property,
                    description);

                if (_directBindings == null)
                {
                    _directBindings = new List <DirectBindingSubscription>();
                }

                return(new DirectBindingSubscription(this, property, source));
            }
            else
            {
                Logger.Verbose(
                    LogArea.Property,
                    this,
                    "Bound {Property} to {Binding} with priority {Priority}",
                    property,
                    description,
                    priority);

                return(Values.AddBinding(property, source, priority));
            }
        }