示例#1
0
        /// <summary>
        /// Invoked when the effective property value of the ViewValue property changes.
        /// </summary>
        /// <param name="dependencyObject">The DependencyObject on which the property has changed value.</param>
        /// <param name="dependencyPropertyChangedEventArgs">Event data that is issued by any event that tracks changes to the effective value of this
        /// property.</param>
        static void OnValuePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Adjust the slider position to reflect the current integral Value using the mapping for the ticks on the slider.
            ViewSlider viewSlider = dependencyObject as ViewSlider;

            if (viewSlider.Value != Int32.MinValue)
            {
                ((Slider)viewSlider).Value = ViewSlider.smallTicks[viewSlider.Value];
            }
        }
示例#2
0
        /// <summary>
        /// Called whenever a dependency property value is being re-evaluated, or coercion is specifically requested.
        /// </summary>
        /// <param name="dependencyObject">The object that the property exists on. When the callback is invoked, the property system will pass this value.</param>
        /// <param name="baseValue">The new value of the property, prior to any coercion attempt.</param>
        /// <returns>The coerced value (with appropriate type).</returns>
        static Object CoerceValuePropertyCallback(DependencyObject dependencyObject, Object baseValue)
        {
            // Extract the slider and the new value from the generic parameters.
            ViewSlider viewSlider = dependencyObject as ViewSlider;
            Double     newValue   = (Double)baseValue;

            // When the mouse is used to move the thumb it will snap into place when it is close to an integral view.  This provides the snapping logic that moves
            // the mouse to an integral position on the slider when it gets close to that value.
            if (!viewSlider.inhibitSnap)
            {
                foreach (Range range in ViewSlider.snappingRange)
                {
                    if (range.Minimum <= newValue && newValue < range.Maximum)
                    {
                        baseValue = range.Value;
                    }
                }
            }

            // When the mouse is not close to a 'Large Tick' position on the slider the value is returned unaltered, but when it is close it will snap into place by
            // coercing the value.
            return(baseValue);
        }
 /// <summary>
 /// Is invoked whenever application code or internal processes call ApplyTemplate.
 /// </summary>
 public override void OnApplyTemplate()
 {
     // Once we've dug down into the templates to find the slider it can be attached to the value property of this control.  Moving the slider will change
     // the value and any listeners attached to the value of this property will see the change also.
     this.viewSlider = this.GetTemplateChild(ViewButtonDropDown.partSlider) as ViewSlider;
 }