示例#1
0
        private void UpdateRangeProperties()
        {
            _rangeConverter.SourceMin   = Minimum;
            _rangeConverter.SourceMax   = Maximum;
            _rangeConverter.ScaleFactor = ScaleFactor;

            Value          = _rangeConverter.ForceIntoSourceRange(Value);
            SliderPosition = _rangeConverter.SourceToTarget(Value);
            //if (Minimum == -1)
            //{
            //    Console.WriteLine(_rangeConverter.SourceToTarget(-1));
            //    Console.WriteLine(_rangeConverter.SourceToTarget(-0.5));
            //    Console.WriteLine(_rangeConverter.SourceToTarget(0));
            //    Console.WriteLine(_rangeConverter.SourceToTarget(0.5));
            //    Console.WriteLine(_rangeConverter.SourceToTarget(1));
            //}
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double dblValue;

            if (value == null)
            {
                return(value);
            }
            if (!double.TryParse(value.ToString(), out dblValue))
            {
                return(value);
            }

            MeteredSlider    ss = parameter as MeteredSlider;
            FrameworkElement fe = parameter as FrameworkElement;

            if (ss == null && fe != null)
            {
                if (fe.DataContext is MeteredSlider)
                {
                    ss = fe.DataContext as MeteredSlider;
                }
                if (fe.Tag is MeteredSlider)
                {
                    ss = fe.Tag as MeteredSlider;
                }
            }

            if (ss == null)
            {
                return(0);
            }

            _converter.SourceMin   = ss.Minimum;
            _converter.SourceMax   = ss.Maximum;
            _converter.ScaleFactor = ss.ScaleFactor;

            double result = _converter.SourceToTarget(dblValue);

            return(result);
        }