コード例 #1
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)
        {
            LevelDisplay level = obj as LevelDisplay;

            if (level == null)
            {
                return;
            }

            level.ValueTextBox.Text = Math.Abs(level.Value).ToString(level.stringFormat);
            level.SetValue(LevelDisplay.PixelValuePropertyKey, level.PixelValue);
        }
コード例 #2
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 LevelDisplayPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            LevelDisplay level = obj as LevelDisplay;

            switch (e.Property.Name)
            {
            case "Labels":
                level.ParseLabels();
                level.RecalculateTicks();
                break;
            }
        }
コード例 #3
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)
        {
            LevelDisplay level = dependencyObject as LevelDisplay;

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

            var newVal = (double)baseValue;

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

            // Make sure it's within our defined range
            newVal = Math.Min(Math.Max(-level.Range, newVal), level.Range);

            return(newVal);
        }