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 <PerspexObject, object, object> validate = property.GetValidationFunc(GetType());
            Func <object, object> validate2 = null;

            if (validate != null)
            {
                validate2 = v => validate(this, v);
            }

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

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

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

                    _propertyLog.Verbose(
                        "{Property} changed from {$Old} to {$Value} with priority {Priority}",
                        property,
                        oldValue,
                        newValue,
                        (BindingPriority)result.ValuePriority);
                }
            });

            return(result);
        }