다음을 통해 공유


Different Ways to Scroll Content in WPF Apps

We had a good thread today at the office about the content scrolling in WPF applications (controls, DataGrid, etc.), and one of our devs, Ben Carter, had a response that I thought is golden and would like to share with you:

Here are a variety of ways to scroll, perhaps one of these would fit the scenario you’re thinking of:

· The default – provide a ScrollViewer and let the end-user do the work.

· BringIntoView – Find a reference to an element and call BringIntoView() on it.

· ScrollIntoView – Some ItemsControls provide a way to specify the data item to bring into view since the element that corresponds to the data item might be virtualized, making BringIntoView not an option.

· ScrollViewer.LineUp, etc. – Find a reference to a ScrollViewer and call the desired scrolling method.

· Commands – Raise one of the ScrollBar routed commands (ScrollBar.LineUpCommand) on an element that is a child of the ScrollViewer. (should result in essentially the same as calling the method on ScrollViewer)

· ScrollBar.Value – Find a reference to a ScrollBar within a ScrollViewer and set the value property directly. (generally not recommended)

He summarized them really well, IMHO.

Comments