Wpf ScrollViewer Scroll Amount

前端 未结 4 838
慢半拍i
慢半拍i 2021-02-05 08:03

Is it possible to change the amount that the WPF ScrollViewer scrolls? I am simply wondering if it\'s possible to change the scrollviewer so that when using the mouse wheel or t

4条回答
  •  一向
    一向 (楼主)
    2021-02-05 08:31

    The short answer is: there is no way to do this without writing some custom scrolling code, but don't let that scare you it's not all that hard.

    The ScrollViewer either works by scrolling using physical units (i.e. pixels) or by engaging with an IScrollInfo implementation to use logical units. This is controlled by the setting the CanContentScroll property where a value of false means "scroll the content using physical units" and a value of true means "scroll the content logically".

    So how does the ScrollViewer scroll the content logically? By communicating with an IScrollInfo implementation. So that's how you could take over exactly how much the content of your panel scrolls when someone performs a logical action. Take a look at the documentation for IScrollInfo to get a listing of all the logical units of measurment that can be requested to scroll, but since you mentioned the mouse wheel you'll be mostly interested in the MouseWheelUp/Down/Left/Right methods.

提交回复
热议问题