Exemplo n.º 1
0
        /// <inheritdoc/>
        protected override void OnArrange(Vector2F position, Vector2F size)
        {
            // Update X or Y of the thumb to slide it to the correct position.
            if (_thumb != null)
            {
                float    value   = Value;
                float    minimum = Minimum;
                float    maximum = Maximum;
                float    range   = maximum - minimum;
                Vector4F padding = Padding;

                if (Orientation == Orientation.Horizontal)
                {
                    float contentWidth = ActualWidth - padding.X - padding.Z;

                    // ViewPortSize determines thumb width.
                    float thumbWidth = contentWidth * ViewportSize;
                    if (thumbWidth < _thumb.MinWidth)
                    {
                        thumbWidth = _thumb.MinWidth;
                    }
                    else if (thumbWidth > _thumb.MaxWidth)
                    {
                        thumbWidth = _thumb.MaxWidth;
                    }

                    _thumb.Width = thumbWidth;
                    _thumb.Measure(new Vector2F(float.PositiveInfinity));

                    // Compute movement range of thumb center.
                    contentWidth = ActualWidth - padding.X - padding.Z - thumbWidth;

                    float thumbCenterPosition = contentWidth / range * (value - Minimum);
                    if (Numeric.AreEqual(minimum, maximum))
                    {
                        thumbCenterPosition = 0;
                    }

                    _thumb.X = padding.X + thumbCenterPosition;
                }
                else
                {
                    float contentHeight = ActualHeight - padding.Y - padding.W;

                    float thumbHeight = contentHeight * ViewportSize;
                    if (thumbHeight < _thumb.MinHeight)
                    {
                        thumbHeight = _thumb.MinHeight;
                    }
                    else if (thumbHeight > _thumb.MaxHeight)
                    {
                        thumbHeight = _thumb.MaxHeight;
                    }

                    _thumb.Height = thumbHeight;
                    _thumb.Measure(new Vector2F(float.PositiveInfinity));

                    contentHeight = ActualHeight - padding.Y - padding.W - thumbHeight;

                    float thumbCenterPosition = contentHeight / range * (value - Minimum);
                    if (Numeric.AreEqual(minimum, maximum))
                    {
                        thumbCenterPosition = 0;
                    }

                    _thumb.Y = padding.Y + thumbCenterPosition;
                }
            }

            base.OnArrange(position, size);
        }