Example #1
0
        protected override void OnInitialized()
        {
            TProperty minProperty = (TProperty)Owner[this.minPropertyName];
            TProperty maxProperty = (TProperty)Owner[this.maxPropertyName];

            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MinValue, maxProperty.MinValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MinValue must be less than or equal to MaxProperty.MinValue");
            }

            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MaxValue, maxProperty.MaxValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MaxValue must be less than or equal to MaxProperty.MaxValue");
            }

            // Analyze the PropertyCollection we are bound to in order to ensure that we do not
            // have any "infinite loops". It is safe to simply ensure that no other SoftMutuallyBoundMinMaxRule
            // has minPropertyName as a maxPropertyName.
            foreach (PropertyCollectionRule rule in this.Owner.Rules)
            {
                SoftMutuallyBoundMinMaxRule <TValue, TProperty> asOurRule = rule as SoftMutuallyBoundMinMaxRule <TValue, TProperty>;

                if (asOurRule != null)
                {
                    if (asOurRule.maxPropertyName.ToString() == this.minPropertyName.ToString())
                    {
                        throw new ArgumentException("The graph of SoftMutuallyBoundMinMaxRule's in the PropertyCollection has a cycle in it");
                    }
                }
            }

            minProperty.ValueChanged += new EventHandler(MinProperty_ValueChanged);
            maxProperty.ValueChanged += new EventHandler(MaxProperty_ValueChanged);
        }
Example #2
0
 protected override bool ValidateNewValueT(T newValue)
 {
     if (ScalarProperty <T> .IsLessThan(newValue, this.minValue))
     {
         return(false);
     }
     if (ScalarProperty <T> .IsGreaterThan(newValue, this.maxValue))
     {
         return(false);
     }
     return(base.ValidateNewValueT(newValue));
 }
Example #3
0
 internal ScalarProperty(object name, T defaultValue, T minValue, T maxValue, bool readOnly, ValueValidationFailureResult vvfResult) : base(name, defaultValue, readOnly, vvfResult)
 {
     if (ScalarProperty <T> .IsLessThan(maxValue, minValue))
     {
         throw new ArgumentOutOfRangeException("maxValue < minValue");
     }
     if (ScalarProperty <T> .IsLessThan(defaultValue, minValue))
     {
         throw new ArgumentOutOfRangeException("defaultValue < minValue");
     }
     if (ScalarProperty <T> .IsGreaterThan(defaultValue, maxValue))
     {
         throw new ArgumentOutOfRangeException("defaultValue > maxValue");
     }
     this.minValue = minValue;
     this.maxValue = maxValue;
 }
Example #4
0
        public static T Clamp(T value, T min, T max)
        {
            T local = value;

            if (ScalarProperty <T> .IsGreaterThan(min, max))
            {
                throw new ArgumentOutOfRangeException("min must be less than or equal to max");
            }
            if (ScalarProperty <T> .IsGreaterThan(value, max))
            {
                local = max;
            }
            if (ScalarProperty <T> .IsLessThan(value, min))
            {
                local = min;
            }
            return(local);
        }
Example #5
0
        protected override void OnInitialized()
        {
            TProperty minProperty = (TProperty)base.Owner[this.minPropertyName];
            TProperty maxProperty = (TProperty)base.Owner[this.maxPropertyName];

            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MinValue, maxProperty.MinValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MinValue must be less than or equal to MaxProperty.MinValue");
            }
            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MaxValue, maxProperty.MaxValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MaxValue must be less than or equal to MaxProperty.MaxValue");
            }
            foreach (SoftMutuallyBoundMinMaxRule <TValue, TProperty> rule in base.Owner.Rules)
            {
                if ((rule != null) && (rule.maxPropertyName.ToString() == this.minPropertyName.ToString()))
                {
                    throw new ArgumentException("The graph of SoftMutuallyBoundMinMaxRule's in the PropertyCollection has a cycle in it");
                }
            }
            minProperty.ValueChanged += (s, e) => ((SoftMutuallyBoundMinMaxRule <TValue, TProperty>) this).OnMinPropertyValueChanged(minProperty, e.Value);
            maxProperty.ValueChanged += (s, e) => ((SoftMutuallyBoundMinMaxRule <TValue, TProperty>) this).OnMaxPropertyValueChanged(maxProperty, e.Value);
        }
Example #6
0
 public static bool IsGreaterThan(ScalarProperty <T> lhs, ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsGreaterThan(lhs.Value, rhs.Value);
Example #7
0
 public bool IsGreaterThan(ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsGreaterThan((ScalarProperty <T>) this, rhs);