コード例 #1
0
ファイル: MultiRangeSlider.cs プロジェクト: X-Lars/ControlsXL
        /// <summary>
        /// Updates the value when the thumb position is changed.
        /// </summary>
        /// <param name="d">The dependency object providing the property that is changed.</param>
        /// <param name="e"></param>
        private static void PositionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MultiRangeSlider slider = (MultiRangeSlider)d;

            if (slider.Orientation == Orientation.Horizontal)
            {
                slider.Value = (((slider.Max - slider.Min) / (slider.ActualWidth - slider._Thumb.ActualWidth / 2)) * slider.Position) + slider.Min;
            }
            else
            {
                slider.Value = (((slider.Max - slider.Min) / (slider.ActualHeight - slider._Thumb.ActualHeight / 2)) * slider.Position) + slider.Min;
            }

            Console.WriteLine(slider.Value);
        }
コード例 #2
0
ファイル: MultiRangeSlider.cs プロジェクト: X-Lars/ControlsXL
        /// <summary>
        /// Invalidates the thumb position limits.
        /// </summary>
        /// <param name="d">The dependency object providing the property to invalidate.</param>
        /// <param name="baseValue">The value to invalidate.</param>
        /// <returns>The invalidated value.</returns>
        private static object CoercePositionProperty(DependencyObject d, object baseValue)
        {
            MultiRangeSlider slider = (MultiRangeSlider)d;
            double           value  = (double)baseValue;

            value = Math.Max(value, 0);

            if (slider.Orientation == Orientation.Horizontal)
            {
                value = Math.Min(value, slider.ActualWidth - slider._Thumb.ActualWidth / 2);
            }
            else
            {
                value = Math.Min(value, slider.ActualHeight - slider._Thumb.ActualHeight / 2);
            }

            return(value);
        }