VerticalScrollBarValue

Introduction

VerticalScrollBarValue is the current value of the ScrollViewer's vertical scroll bar. This value returns the current scroll bar value, and it can be assigned to force the scroll position.

This range for this value is between 0 and VerticalScrollBarMaximum.

Code Example - Getting VerticalScrollBarValue

The following code gets the VerticalScrollBarValue and displays it using a Label.

var label = new Label();
mainPanel.AddChild(label);

var scrollViewer = new ScrollViewer();
scrollViewer.InnerPanel.StackSpacing = 3;

for(int i = 0; i < 20; i++)
{
    var coloredRectangle = new ColoredRectangleRuntime();
    coloredRectangle.Color = Color.Red;
    scrollViewer.AddChild(coloredRectangle);
}

scrollViewer.ScrollChanged += (sender, args) =>
{
    label.Text = 
        $"Scroll position: {scrollViewer.VerticalScrollBarValue}/" +
        $"{scrollViewer.VerticalScrollBarMaximum}";
};
mainPanel.AddChild(scrollViewer);

Last updated

Was this helpful?