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)
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)
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.
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
<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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With