Item by item scrolling in a WPF Listview

前端 未结 1 1605
攒了一身酷
攒了一身酷 2021-01-12 21:52

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条回答
  •  春和景丽
    2021-01-12 22:19

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

    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:

    Handle the PreviewMouseWheel event on ListBox

    
        

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

    Therefore, you turned the MouseWheel scroll into the LineDown/LineUp.

    0 讨论(0)
提交回复
热议问题