Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is indeed possible to do what you're asking, though it will require a fair amount of custom code. </p> <p>Normally in WPF a ScrollViewer uses what is known as Logical Scrolling, which means it's going to scroll item by item instead of by an offset amount. The other answers cover some of the ways you can change the Logical Scrolling behavior into that of Physical Scrolling. The other way is to make use of the ScrollToVertialOffset and ScrollToHorizontalOffset methods exposed by both ScrollViwer and IScrollInfo. </p> <p>To implement the larger part, the scrolling when the mouse wheel is pressed, we will need to make use of the MouseDown and MouseMove events.</p> <pre class="lang-xml prettyprint-override"><code>&lt;ListView x:Name="uiListView" Mouse.MouseDown="OnListViewMouseDown" Mouse.MouseMove="OnListViewMouseMove" ScrollViewer.CanContentScroll="False"&gt; .... &lt;/ListView&gt; </code></pre> <p>In the MouseDown, we are going to record the current mouse position, which we will use as a relative point to determine which direction we scroll in. In the mouse move, we are going to get the ScrollViwer component of the ListView and then Scroll it accordingly.</p> <pre><code>private Point myMousePlacementPoint; private void OnListViewMouseDown(object sender, MouseButtonEventArgs e) { if (e.MiddleButton == MouseButtonState.Pressed) { myMousePlacementPoint = this.PointToScreen(Mouse.GetPosition(this)); } } private void OnListViewMouseMove(object sender, MouseEventArgs e) { ScrollViewer scrollViewer = ScrollHelper.GetScrollViewer(uiListView) as ScrollViewer; if (e.MiddleButton == MouseButtonState.Pressed) { var currentPoint = this.PointToScreen(Mouse.GetPosition(this)); if (currentPoint.Y &lt; myMousePlacementPoint.Y) { scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - 3); } else if (currentPoint.Y &gt; myMousePlacementPoint.Y) { scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + 3); } if (currentPoint.X &lt; myMousePlacementPoint.X) { scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset - 3); } else if (currentPoint.X &gt; myMousePlacementPoint.X) { scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + 3); } } } public static DependencyObject GetScrollViewer(DependencyObject o) { // Return the DependencyObject if it is a ScrollViewer if (o is ScrollViewer) { return o; } for (int i = 0; i &lt; VisualTreeHelper.GetChildrenCount(o); i++) { var child = VisualTreeHelper.GetChild(o, i); var result = GetScrollViewer(child); if (result == null) { continue; } else { return result; } } return null; } </code></pre> <p>There's some areas it's lacking as it's just a proof of concept but it should definitely get you started in the right direction. To have it constantly scroll once the mouse is moved away from the initial MouseDown point, the scrolling logic could go into a DispatcherTimer or something similar.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload