WPF ListBox控件在代码中水平滚动 [英] WPF ListBox control horizontal scrolling in code

查看:289
本文介绍了WPF ListBox控件在代码中水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在代码中设置列表框的水平滚动位置?我在项目模板中有一个带有包装板的列表框,我想实现一个向右翻页"功能,该功能的行为类似于普通列表中的向下翻页,但可以横向使用.

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.

谢谢!

推荐答案

通过在网站上进行更多搜索,我找到了问题的答案.

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

在Josh G对此问题的答案中使用以下功能

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

使用该功能通过代码向左和向右翻页,下面就是您要做的(其中listBox是我的ListBox控件的名称),

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

这篇关于WPF ListBox控件在代码中水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆