WPF ListBox control horizontal scrolling in code

半腔热情 提交于 2019-12-11 02:48:16

问题


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!


回答1:


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();
}



回答2:


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



来源:https://stackoverflow.com/questions/1556013/wpf-listbox-control-horizontal-scrolling-in-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!