按项目在WPF列表视图滚动项目 [英] Item by item scrolling in a WPF Listview

查看:172
本文介绍了按项目在WPF列表视图滚动项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView在高度上相当小,但有3-4 listviewitems这会占用ListView控件(所以只有一个项目可以同时显示)

I have a listview which is quite small in height, but has 3-4 listviewitems which takes up the whole size of the Listview (so only one item can be displayed at once)

而如果它的用户滚动,列表视图没有一次滚动项目1项,它一次(单条)滚动2项

And if the user scrolls on it, the listview doesn't scroll 1 item at a time, it scrolls 2 items at a time (single scroll)

你将如何设置它使1卷=一个项目下/上?

How would you set it so 1 scroll = one item down/up?

希望我讲明白了这一点,如果不告诉我。

Hope I made myself clear with this, if not just tell me.

推荐答案

我假设你在谈论这里的鼠标滚轮滚动。

I assume you're talking about the MouseWheel scroll here.

鼠标滚轮的滚动实际上取决于 IScrollInfo 的实施。我建议你​​给自己办理的鼠标滚轮的事件的ScrollViewer 不前。因此,基本上,你可以不喜欢以下内容:

The MouseWheel scroll really depends on the IScrollInfo implementation. I suggest you to handle the MouseWheel event yourself before the ScrollViewer does. So basically, you could do something like following:

手柄 PreviewMouseWheel 事件列表框

Handle the PreviewMouseWheel event on ListBox

<ListBox PreviewMouseWheel="ListBox_PreviewMouseWheel" Height="108" Width="100" x:Name="list" >
    <Button Content="Button 1" Height="100"/>
    <Button Content="Button 2" Height="100"/>
    <Button Content="Button 3" Height="100"/>
    <Button Content="Button 4" Height="100"/>
    <Button Content="Button 5" Height="100"/>
    <Button Content="Button 6" Height="100"/>
    <Button Content="Button 7" Height="100"/>
    <Button Content="Button 8" Height="100"/>
    <Button Content="Button 9" Height="100"/>
</ListBox>

在后面的代码,火 ScrollBar.LineDownCommand ScrollBar.LineUpCommand 当您滚动向下或向上。

In the code behind, fire the ScrollBar.LineDownCommand or ScrollBar.LineUpCommand when you scroll down or up.

private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
    if (e.Delta > 0)
    {
        ScrollBar.LineDownCommand.Execute(null, e.OriginalSource as IInputElement);
    }
    if (e.Delta < 0)
    {
        ScrollBar.LineUpCommand.Execute(null, e.OriginalSource as IInputElement);
    }
    e.Handled = true;
}



因此​​,你转身的鼠标滚轮的滚动进入的 LineDown /系列

这篇关于按项目在WPF列表视图滚动项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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