2

How can I set the horizontal scroll position of a list box in code? I have a list box with a wrap panel in the items template and I want to implement a 'page right' function that behaves like a page down down in a normal list but works sideways.

Thanks!

2 Answers 2

2

With some more searching around the site, I figured out the answer to my question.

Using the following function from Josh G's answer to this question

public static childItem FindVisualChild<childItem>(DependencyObject obj)
{
     ...
}  

With that function to page left and right via code, this is all you have to do is the following (where listBox is the name of my ListBox control),

void PageRight()
{
    ScrollViewer myScrollviewer = FindVisualChild<ScrollViewer>(listBox);
    myScrollviewer.PageRight();
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the ScrollIntoView method to scroll a specific item into view

1 Comment

How would you be able to tell if that was the first item that wasn't in view, so it could preform like a 'page down'? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.