开发者

Detect UP and DOWN arrow button clicks on WPF ListView

开发者 https://www.devze.com 2023-04-03 13:24 出处:网络
I have a very simple ListView which b开发者_如何学编程inds to an ObservableCollection of strings. I can use the \'ScrollBar.Scroll\' property to detect when someone clicks on the scroll bar and tugs i

I have a very simple ListView which b开发者_如何学编程inds to an ObservableCollection of strings. I can use the 'ScrollBar.Scroll' property to detect when someone clicks on the scroll bar and tugs it up or down, but how do you detect when they click the UP or DOWN buttons at the top and bottom of the ScrollBar? Clicking these does not seem to fire the Scroll event.

I'm sure it must be something straight-forward, but I've searched for about an hour without success.

TIA


Try this

private void listView_ScrollChanged(object sender, ScrollChangedEventArgs e) {

listView.selectedIndex = Convert.Int16(e.VerticalOffset) }


You can use the attached event ScrollViewer.ScrollChanged

Example

<ListView ScrollViewer.ScrollChanged="listView_ScrollChanged"
          ... />

Event handler

private void listView_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    // You will end up here everytime the `ListView` is scrolled
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号