/// <summary> /// Initializes a new instance of the <see cref="PriorityLevel"/> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="priority">The priority.</param> public PriorityLevel( PriorityValue owner, int priority) { Contract.Requires <ArgumentNullException>(owner != null); _owner = owner; Priority = priority; Value = _directValue = PerspexProperty.UnsetValue; ActiveBindingIndex = -1; Bindings = new LinkedList <PriorityBindingEntry>(); }
/// <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) { var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(GetType()); Func <object, object> validate2 = null; if (validate != null) { validate2 = v => validate(this, v); } PriorityValue result = new PriorityValue( this, property, property.PropertyType, validate2); return(result); }
/// <summary> /// Sets a <see cref="PerspexProperty"/> value. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value.</param> public void SetValue(PerspexProperty property, object value) { Contract.Requires <NullReferenceException>(property != null); const int Priority = (int)BindingPriority.LocalValue; PriorityValue v; if (!this.IsRegistered(property)) { throw new InvalidOperationException(string.Format( "Property '{0}' not registered on '{1}'", property.Name, this.GetType())); } if (!PriorityValue.IsValidValue(value, property.PropertyType)) { throw new InvalidOperationException(string.Format( "Invalid value for Property '{0}': {1} ({2})", property.Name, value, value.GetType().FullName)); } if (!this.values.TryGetValue(property, out v)) { if (value == PerspexProperty.UnsetValue) { return; } v = this.CreatePriorityValue(property); this.values.Add(property, v); } this.Log().Debug( "Set local value of {0}.{1} (#{2:x8}) to {3}", this.GetType().Name, property.Name, this.GetHashCode(), value); v.Replace(Observable.Never <object>().StartWith(value), Priority); }
/// <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) { var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(GetType()); Func <object, object> validate2 = null; if (validate != null) { validate2 = v => validate(this, v); } PriorityValue result = new PriorityValue( this, 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); Logger.Verbose( LogArea.Property, this, "{Property} changed from {$Old} to {$Value} with priority {Priority}", property, oldValue, newValue, (BindingPriority)result.ValuePriority); } }); return(result); }
/// <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); }