Exemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="PriorityValue"/> for a <see cref="PerspexProperty"/>.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>The <see cref="PriorityValue"/>.</returns>
        private PriorityValue CreatePriorityValue(PerspexProperty property)
        {
            Func <object, object> coerce = null;

            if (property.Coerce != null)
            {
                coerce = v => property.Coerce(this, v);
            }

            PriorityValue result = new PriorityValue(property.Name, property.PropertyType, coerce);

            result.Changed.Subscribe(x =>
            {
                object oldValue = (x.Item1 == PerspexProperty.UnsetValue) ?
                                  this.GetDefaultValue(property) :
                                  x.Item1;
                object newValue = (x.Item2 == PerspexProperty.UnsetValue) ?
                                  this.GetDefaultValue(property) :
                                  x.Item2;

                if (!object.Equals(oldValue, newValue))
                {
                    this.RaisePropertyChanged(property, oldValue, newValue, (BindingPriority)result.ValuePriority);

                    this.Log().Debug(
                        "Value of {0}.{1} (#{2:x8}) changed from {3} to {4}",
                        this.GetType().Name,
                        property.Name,
                        this.GetHashCode(),
                        oldValue,
                        newValue);
                }
            });

            return(result);
        }