private void UpdateLowerValue(double value)
        {
            CoercedValues cv       = this.GetCoercedValues();
            double        newValue = Math.Max(cv.Minimum, Math.Min(cv.Maximum, value));

            newValue = Math.Min(newValue, cv.HigherValue);
            this.SetLowerSliderValues(newValue, null, null);
            this.LowerValue = newValue;
        }
        private void UpdateHigherValue(double?value)
        {
            CoercedValues cv       = this.GetCoercedValues();
            double        newValue = Math.Max(cv.Minimum, Math.Min(cv.Maximum, value.HasValue ? value.Value : 0d));

            newValue = Math.Max(newValue, cv.LowerValue);
            this.SetHigherSliderValues(newValue, null, null);
            this.HigherValue = newValue;
        }
Example #3
0
 private void HigherSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (_higherSlider.IsLoaded)
     {
         CoercedValues cv       = this.GetCoercedValues();
         double        newValue = Math.Max(cv.Minimum, Math.Min(cv.Maximum, e.NewValue));
         newValue = Math.Max(newValue, cv.LowerValue);
         this.SetHigherSliderValues(newValue, null, null);
         this.HigherValue = newValue;
     }
 }
        private CoercedValues GetCoercedValues()
        {
            CoercedValues cv = new CoercedValues();

            cv.Minimum     = Math.Min(this.Minimum, this.Maximum);
            cv.Maximum     = Math.Max(cv.Minimum, this.Maximum);
            cv.LowerValue  = Math.Max(cv.Minimum, Math.Min(cv.Maximum, this.LowerValue));
            cv.HigherValue = Math.Max(cv.Minimum, Math.Min(cv.Maximum, this.HigherValue));
            cv.HigherValue = Math.Max(cv.LowerValue, cv.HigherValue);

            return(cv);
        }
        private void HigherRange_Click(object sender, RoutedEventArgs e)
        {
            CoercedValues cv = this.GetCoercedValues();

            //When Maximum is not greater than Minimum, the
            //slider display is in an inconsistant state. Don't
            //consider any operation from the user
            if (cv.Minimum < cv.Maximum)
            {
                double newValue = cv.HigherValue + this.Step;
                this.HigherValue = Math.Min(cv.Maximum, Math.Max(cv.Minimum, newValue));
            }
        }
        private void AdjustView()
        {
            //Coerce values to make them consistent.
            CoercedValues cv = this.GetCoercedValues();

            double actualWidth            = 0;
            double lowerSliderThumbWidth  = 0d;
            double higherSliderThumbWidth = 0d;

            if (this.Orientation == Orientation.Horizontal)
            {
                actualWidth            = this.ActualWidth;
                lowerSliderThumbWidth  = RangeSlider.GetThumbWidth(_lowerSlider);
                higherSliderThumbWidth = RangeSlider.GetThumbWidth(_higherSlider);
            }
            else if (this.Orientation == Orientation.Vertical)
            {
                actualWidth            = this.ActualHeight;
                lowerSliderThumbWidth  = RangeSlider.GetThumbHeight(_lowerSlider);
                higherSliderThumbWidth = RangeSlider.GetThumbHeight(_higherSlider);
            }

            actualWidth -= (lowerSliderThumbWidth + higherSliderThumbWidth);

            this.SetLowerSliderValues(cv.LowerValue, cv.Minimum, cv.Maximum);
            this.SetHigherSliderValues(cv.HigherValue, cv.Minimum, cv.Maximum);

            double entireRange = cv.Maximum - cv.Minimum;

            if (entireRange > 0)
            {
                this.HigherRangeWidth = (actualWidth * (cv.Maximum - cv.HigherValue)) / entireRange;

                this.RangeWidth = (actualWidth * (cv.HigherValue - cv.LowerValue)) / entireRange;

                this.LowerRangeWidth = (actualWidth * (cv.LowerValue - cv.Minimum)) / entireRange;
            }
            else
            {
                this.HigherRangeWidth = 0d;
                this.RangeWidth       = 0d;
                this.LowerRangeWidth  = actualWidth;
            }
        }
      private CoercedValues GetCoercedValues()
      {
        CoercedValues cv = new CoercedValues();
        cv.Minimum = Math.Min( this.Minimum, this.Maximum );
        cv.Maximum = Math.Max( cv.Minimum, this.Maximum );
        cv.LowerValue = Math.Max( cv.Minimum, Math.Min( cv.Maximum, this.LowerValue ) );
        cv.HigherValue = Math.Max( cv.Minimum, Math.Min( cv.Maximum, this.HigherValue ) );
        cv.HigherValue = Math.Max( cv.LowerValue, cv.HigherValue );

        return cv;
      }