Exemple #1
0
        /// <summary>
        /// Called by the dependency property when any of the slider properties have changed.
        /// </summary>
        /// <param name="obj">The slider object that caused the change.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void SliderPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            bool        callLabelRecalc = true;
            RangeSlider slider          = obj as RangeSlider;

            switch (e.Property.Name)
            {
            case "Maximum":
            case "Minimum":
            case "TickStart":
            case "TickEnd":
            case "TickMinorSpacing":
            case "TickMajorSpacing":
                // No extra processing neccessary
                break;

            case "TickLabels":
                slider.ParseLabels();
                break;

            default:
                callLabelRecalc = false;
                break;
            }

            if (callLabelRecalc)
            {
                slider.RecalculateLabelsAndTicks();
            }
        }
Exemple #2
0
        /// <summary>
        /// Called by the dependency property when the Value has changed.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void LimitsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            RangeSlider slider = obj as RangeSlider;

            if (slider == null)
            {
                return;
            }

            slider.CalculatePartHeights();
        }
Exemple #3
0
        /// <summary>
        /// Called by the dependency property when the Value has changed.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void ValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            RangeSlider slider = obj as RangeSlider;

            if (slider == null)
            {
                return;
            }
            if (slider.ActualHeight > 0)
            {
                double valueYPos = slider.UsableSize * slider.GetLocation(slider.Value);
                slider.SetValue(RangeSlider.ValueMarginPropertyKey, new Thickness(slider.IsVertical ? 0 : valueYPos, slider.IsVertical ? valueYPos : 0, 0, 0));
            }
        }
Exemple #4
0
        /// <summary>
        /// Coerces the given value to a valid range.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="baseValue">The base value.</param>
        /// <returns></returns>
        private static object CoerceValueCallback(DependencyObject dependencyObject, object baseValue)
        {
            RangeSlider slider = dependencyObject as RangeSlider;

            if (slider == null)
            {
                return(null);
            }

            var newVal = (double)baseValue;

            // Check if we need to round it
            if (slider.rounder != 0.0)
            {
                newVal = Math.Round(slider.rounder * newVal) / slider.rounder;
            }

            // Make sure it's within our defined range
            newVal = Math.Min(Math.Max(slider.Minimum, newVal), slider.Maximum);

            return(newVal);
        }