示例#1
0
        private void OnScrollBarValueChanged(System.Windows.Controls.Primitives.ScrollBar scrollBar, ScrollBarParameter parameter)
        {
            if (scrollBar != null)
            {
                double oldThumbLength = scrollBar.GetThumbLength();
                double oldThumbCenter = scrollBar.GetThumbCenter();
                double newThumbLength = parameter.EndValue - parameter.StartValue;
                double newThumbCenter = (parameter.StartValue + parameter.EndValue) / 2;
                bool   newEnabled     = (parameter.StartValue > 0 || parameter.EndValue < 1);
                double newMaximuum    = newEnabled ? 1 : 0;

                if (oldThumbLength != newThumbLength ||
                    oldThumbCenter != newThumbCenter ||
                    scrollBar.SmallChange != parameter.SmallChange ||
                    scrollBar.LargeChange != parameter.LargeChange ||
                    scrollBar.IsEnabled != newEnabled ||
                    scrollBar.Maximum != newMaximuum)
                {
                    scrollBar.IsEnabled   = newEnabled;
                    scrollBar.Maximum     = newMaximuum;
                    scrollBar.SmallChange = parameter.SmallChange;
                    scrollBar.LargeChange = parameter.LargeChange;
                    scrollBar.SetThumbLength(newThumbLength);
                    scrollBar.SetThumbCenter(newThumbCenter);
                }
            }
        }
示例#2
0
        private (double startValue, double endValue) GetValueRange(System.Windows.Controls.Primitives.ScrollBar scrollBar)
        {
            double thumbLength = scrollBar.GetThumbLength();
            double thumbCenter = scrollBar.GetThumbCenter();

            double startValue = thumbCenter - thumbLength / 2;
            double endValue   = thumbCenter + thumbLength / 2;

            double sv = startValue < 0 ? 0 : startValue > 1 ? 1 : startValue;
            double ev = endValue < 0 ? 0 : endValue > 1 ? 1 : endValue;

            return(sv, ev);
        }