Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
13 lines (11 sloc) 61.5 KB
---
serial: wpf-tips-n-tricks
title: WPF Tips n' Tricks – Preventing ScrollViewer from handling the mouse wheel
date: '2007-09-03T12:17:00.001+01:00'
tags: [wpf]
modified_time: '2007-09-03T12:17:11.791+01:00'
blogger_id: tag:blogger.com,1999:blog-4015568221071268916.post-6582506364125581412
comments: true
blogger_orig_url: http://serialseb.blogspot.com/2007/09/wpf-tips-6-preventing-scrollviewer-from.html
---
<p>In the category of the pot talking to the pan, I present you <a href="http://msdn2.microsoft.com/System.Windows.Controls.ScrollViewer">ScrollViewer</a>. It's the main control to implement scrolling in your templates, but it's also the one not respecting a very&nbsp; fundamental rule of scrolling: if you're done scrolling, let your parent scroll!</p> <p>Not only does ScrollViewer handles the mouse scrolling even when no more scrolling is needed, but it also does so when there's nothing to scroll, or worse when it is told not to scroll! Let's take an example XAML file.&nbsp;</p> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">Window</span><span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">="CaffeineIT.Blog.ScrollViewerExample.Window1"</span></p> <p style="margin: 0px">&nbsp;&nbsp; <span style="color: red">xmlns</span><span style="color: blue">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></p> <p style="margin: 0px">&nbsp;&nbsp; <span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">="http://schemas.microsoft.com/winfx/2006/xaml"</span></p> <p style="margin: 0px">&nbsp;&nbsp; <span style="color: red">Title</span><span style="color: blue">="Window1"</span><span style="color: red"> Height</span><span style="color: blue">="423"</span><span style="color: red"> Width</span><span style="color: blue">="596"&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ScrollViewer</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ScrollViewer</span><span style="color: red"> Name</span><span style="color: blue">="NoScrollingScrollViewer"&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Content that doesn't need scrolling</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ScrollViewer</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ScrollViewer</span><span style="color: red"> Height</span><span style="color: blue">="235"</span><span style="color: red"> Name</span><span style="color: blue">="ScrollingNeededScrollViewer"&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ListView</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Thrid ListView</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Thrid ListView</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Thrid ListView</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Thrid ListView</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Thrid ListView</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Thrid ListView</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ListView</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside Second ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ScrollViewer</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span><span style="color: #a31515">Inside First ScrollViewer</span><span style="color: blue">&lt;/</span><span style="color: #a31515">TextBlock</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ScrollViewer</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">Window</span><span style="color: blue">&gt;</span></p></div> <p>How can we change the ScrollViewer to behave more like it's supposed to?&nbsp;The most direct approach is to leverage&nbsp;the tunneling&nbsp;and bubbling&nbsp;events and use them against the buggy control. </p> <p>The idea is that if the <a href="http://msdn2.microsoft.com/System.Windows.IInputElement.PreviewMouseWheel" rel="nofollow">PreviewMouseWheel</a> is handled, WPF will not generate the MouseWheel event, and in turn the ScrollViewer will not scroll.</p> <p>Let's add a handler for the PreviewMouseWheel event on one of our ScrollViewers.</p> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">ScrollViewer</span><span style="color: red"> Height</span><span style="color: blue">="235"</span><span style="color: red"> Name</span><span style="color: blue">="ScrollingNeededScrollViewer"</span><span style="color: red"> PreviewMouseWheel</span><span style="color: blue">="HandlePreviewMouseWheel"&gt;</span></p> <p style="margin: 0px"><span style="color: blue"></span>&nbsp;</p></div> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">void</span> HandlePreviewMouseWheel(<span style="color: blue">object</span> sender, <span style="color: #2b91af">MouseWheelEventArgs</span> e)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (sender <span style="color: blue">is</span> <span style="color: #2b91af">ScrollViewer</span> &amp;&amp; !e.Handled)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.Handled = <span style="color: blue">true</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> eventArg = <span style="color: blue">new</span> <span style="color: #2b91af">MouseWheelEventArgs</span>(e.MouseDevice, e.Timestamp, e.Delta);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.RoutedEvent = <span style="color: #2b91af">UIElement</span>.MouseWheelEvent;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.Source = sender;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> parent = ((<span style="color: #2b91af">Control</span>)sender).Parent <span style="color: blue">as</span> <span style="color: #2b91af">UIElement</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parent.RaiseEvent(eventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div> <p>This does exactly what we want. It marks the <em>tunneling </em>PreviewMouseWheel event as handled, so as to prevent&nbsp;WPF from raising&nbsp;the <em>bubbling</em> MouseWheel event, which is the one causing the actual scrolling. This is fine in case you don't want a ScrollViewer to scroll at all and let its parent do the scrolling, but what if you only want your ScrollViewer to scroll until it cannot anymore, and then let the parent scroll (this is the behavior in Internet Explorer)? Let's tweak the code a bit.</p> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">void</span> HandlePreviewMouseWheel(<span style="color: blue">object</span> sender, <span style="color: #2b91af">MouseWheelEventArgs</span> e)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> scrollControl = sender <span style="color: blue">as</span> <span style="color: #2b91af">ScrollViewer</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (!e.Handled &amp;&amp; sender != <span style="color: blue">null</span>)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">bool</span> cancelScrolling = <span style="color: blue">false</span>;</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> ((e.Delta &gt; 0 &amp;&amp; scrollControl.VerticalOffset == 0)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; || (e.Delta &lt;= 0 &amp;&amp; scrollControl.VerticalOffset &gt;= scrollControl.ExtentHeight - scrollControl.ViewportHeight))</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.Handled = <span style="color: blue">true</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> eventArg = <span style="color: blue">new</span> <span style="color: #2b91af">MouseWheelEventArgs</span>(e.MouseDevice, e.Timestamp, e.Delta);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.RoutedEvent = <span style="color: #2b91af">UIElement</span>.MouseWheelEvent;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.Source = sender;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> parent = ((<span style="color: #2b91af">Control</span>)sender).Parent <span style="color: blue">as</span> <span style="color: #2b91af">UIElement</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parent.RaiseEvent(eventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div> <p>Now, we check on every mouse wheel scroll if any content needs scrolling in the direction the wheel was scrolled. We check the VerticalOffset property, as it is 0 when you can't scroll up anymore and ExtentHeight-ViewportHeight when you can't scroll down anymore. If there's nothing to scroll, we cancel the event and re-raise it just like we did before.</p> <p>That's all well so far, but what if I have another child ScrollViewer, like the ListView in our example? The ListView will not receive any notifications if the parent ScrollViewer is scrolled to the max in either direction, because we stop the PreviewMouseWheel before it can reach the ListView. We need to change the code a bit more and do the work the framework would've done.</p> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">void</span> HandlePreviewMouseWheel(<span style="color: blue">object</span> sender, <span style="color: #2b91af">MouseWheelEventArgs</span> e)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> scrollControl = sender <span style="color: blue">as</span> <span style="color: #2b91af">ScrollViewer</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (!e.Handled &amp;&amp; sender != <span style="color: blue">null</span> &amp;&amp; !_reentrantList.Contains(e))</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> previewEventArg = <span style="color: blue">new</span> <span style="color: #2b91af">MouseWheelEventArgs</span>(e.MouseDevice, e.Timestamp, e.Delta)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RoutedEvent = <span style="color: #2b91af">UIElement</span>.PreviewMouseWheelEvent,</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Source = sender</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> originalSource = e.OriginalSource <span style="color: blue">as</span> <span style="color: #2b91af">UIElement</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _reentrantList.Add(previewEventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; originalSource.RaiseEvent(previewEventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _reentrantList.Remove(previewEventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green">// at this point if no one else handled the event in our children, we do our job</span></p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (!previewEventArg.Handled &amp;&amp; ((e.Delta &gt; 0 &amp;&amp; scrollControl.VerticalOffset == 0)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; || (e.Delta &lt;= 0 &amp;&amp; scrollControl.VerticalOffset &gt;= scrollControl.ExtentHeight - scrollControl.ViewportHeight)))</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.Handled = <span style="color: blue">true</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> eventArg = <span style="color: blue">new</span> <span style="color: #2b91af">MouseWheelEventArgs</span>(e.MouseDevice, e.Timestamp, e.Delta);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.RoutedEvent = <span style="color: #2b91af">UIElement</span>.MouseWheelEvent;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.Source = sender;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> parent = ((<span style="color: #2b91af">Control</span>)sender).Parent <span style="color: blue">as</span> <span style="color: #2b91af">UIElement</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parent.RaiseEvent(eventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div> <p>The main difference is that before we try to cancel the PreviewMouseWheel event by marking it Handled, we check if any child of the control would mark it Handled before us, which by WPF design would mean we shouldn't handle the event at all.</p> <p>If you try this example now, you'll notice now&nbsp;that our ListView still prevents the scrolling to happen properly. That's because we only changed the behavior of the ScrollViewer we attached an event handler to, and not the one inside the ListView. Using the <a href="http://serialseb.blogspot.com/2007/01/attached-events-by-example-adding.html">attached property initialization hack we used before</a>, we can define an attached property that will do all the hookup work whenever attached to a ScrollViewer.</p> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">ScrollViewerCorrector</span></p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">bool</span> GetFixScrolling(<span style="color: #2b91af">DependencyObject</span> obj)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> (<span style="color: blue">bool</span>)obj.GetValue(FixScrollingProperty);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> SetFixScrolling(<span style="color: #2b91af">DependencyObject</span> obj, <span style="color: blue">bool</span> value)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; obj.SetValue(FixScrollingProperty, value);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">readonly</span> <span style="color: #2b91af">DependencyProperty</span> FixScrollingProperty =</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af">DependencyProperty</span>.RegisterAttached(<span style="color: #a31515">"FixScrolling"</span>, <span style="color: blue">typeof</span>(<span style="color: blue">bool</span>), <span style="color: blue">typeof</span>(<span style="color: #2b91af">ScrollViewerCorrector</span>), <span style="color: blue">new</span> <span style="color: #2b91af">FrameworkPropertyMetadata</span>(<span style="color: blue">false</span>,<span style="color: #2b91af">ScrollViewerCorrector</span>.OnFixScrollingPropertyChanged));</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> OnFixScrollingPropertyChanged(<span style="color: blue">object</span> sender, <span style="color: #2b91af">DependencyPropertyChangedEventArgs</span> e)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af">ScrollViewer</span> viewer = sender <span style="color: blue">as</span> <span style="color: #2b91af">ScrollViewer</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (viewer == <span style="color: blue">null</span>)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">ArgumentException</span>(<span style="color: #a31515">"The dependency property can only be attached to a ScrollViewer"</span>, <span style="color: #a31515">"sender"</span>);</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> ((<span style="color: blue">bool</span>)e.NewValue == <span style="color: blue">true</span>)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.PreviewMouseWheel += HandlePreviewMouseWheel;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">else</span> <span style="color: blue">if</span> ((<span style="color: blue">bool</span>)e.NewValue == <span style="color: blue">false</span>)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.PreviewMouseWheel -= HandlePreviewMouseWheel;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">MouseWheelEventArgs</span>&gt; _reentrantList = <span style="color: blue">new</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">MouseWheelEventArgs</span>&gt;();</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">void</span> HandlePreviewMouseWheel(<span style="color: blue">object</span> sender, <span style="color: #2b91af">MouseWheelEventArgs</span> e)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> scrollControl = sender <span style="color: blue">as</span> <span style="color: #2b91af">ScrollViewer</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (!e.Handled &amp;&amp; sender != <span style="color: blue">null</span> &amp;&amp; !_reentrantList.Contains(e))</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> previewEventArg = <span style="color: blue">new</span> <span style="color: #2b91af">MouseWheelEventArgs</span>(e.MouseDevice, e.Timestamp, e.Delta)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RoutedEvent = <span style="color: #2b91af">UIElement</span>.PreviewMouseWheelEvent,</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Source = sender</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> originalSource = e.OriginalSource <span style="color: blue">as</span> <span style="color: #2b91af">UIElement</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _reentrantList.Add(previewEventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; originalSource.RaiseEvent(previewEventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _reentrantList.Remove(previewEventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green">// at this point if no one else handled the event in our children, we do our job</span></p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (!previewEventArg.Handled &amp;&amp; ((e.Delta &gt; 0 &amp;&amp; scrollControl.VerticalOffset == 0)</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; || (e.Delta &lt;= 0 &amp;&amp; scrollControl.VerticalOffset &gt;= scrollControl.ExtentHeight - scrollControl.ViewportHeight)))</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.Handled = <span style="color: blue">true</span>;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> eventArg = <span style="color: blue">new</span> <span style="color: #2b91af">MouseWheelEventArgs</span>(e.MouseDevice, e.Timestamp, e.Delta);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.RoutedEvent = <span style="color: #2b91af">UIElement</span>.MouseWheelEvent;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eventArg.Source = sender;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> parent = (<span style="color: #2b91af">UIElement</span>)((<span style="color: #2b91af">FrameworkElement</span>)sender).Parent;</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parent.RaiseEvent(eventArg);</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p style="margin: 0px">&nbsp;&nbsp;&nbsp; }</p></div> <p>And the only thing left to do is to change the template for ScrollViewer to always define the attached property by adding the Style to the resources on the Window, and pronto, all your ScrollViewers are now behaving properly.</p> <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"> <p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">Window</span><span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">="CaffeineIT.Blog.ScrollViewerExample.Window1"</span></p> <p style="margin: 0px">&nbsp;&nbsp; <span style="color: red">xmlns</span><span style="color: blue">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></p> <p style="margin: 0px">&nbsp;&nbsp; <span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">="http://schemas.microsoft.com/winfx/2006/xaml"</span></p> <p style="margin: 0px">&nbsp;&nbsp; <span style="color: red">Title</span><span style="color: blue">="Window1"</span><span style="color: red"> Height</span><span style="color: blue">="423"</span><span style="color: red"> Width</span><span style="color: blue">="596"</span><span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">my</span><span style="color: blue">="clr-namespace:CaffeineIT.Blog.ScrollViewerExample"&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Window.Resources</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Style</span><span style="color: red"> TargetType</span><span style="color: blue">="{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type</span><span style="color: red"> ScrollViewer</span><span style="color: blue">}"&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Style.Setters</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Setter</span><span style="color: red"> Property</span><span style="color: blue">="my:ScrollViewerCorrector.FixScrolling"</span><span style="color: red"> Value</span><span style="color: blue">="True" /&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Style.Setters</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Style</span><span style="color: blue">&gt;</span></p> <p style="margin: 0px"><span style="color: #a31515">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Window.Resources</span><span style="color: blue">&gt;</span></p></div> <p>As usual, you can download the <a href="http://www.box.net/shared/v8z3jjvzka">ScrollViewerFixer.zip</a>&nbsp;code and sample.</p>