#676 – MouseWheel Event Is Fired for Element That Mouse Pointer Is Over

When the user rotates the mouse wheel, the PreviewMouseWheel and MouseWheel events will fire.  The PreviewMouseWheel event tunnels down the logical tree, firing for the topmost element and working down to the element that the mouse pointer was located over when the mouse wheel was rotated.  The MouseWheel event then fires, bubbling up the logical tree and firing for each element until the topmost element is reached.

In the example below, if the user rotates the mouse wheel while the mouse pointer is over the Button, the event sequence is:

  • PreviewMouseWheel for Window
  • PreviewMouseWheel for StackPanel
  • PreviewMouseWheel for Button
  • MouseWheel for  Button
  • MouseWheel for StackPanel
  • MouseWheel for Window
<Window Name="win1" x:Class="WpfApplication1.MainWindow"
        Title="Mouse Wheel"
        Width="350" Height="200"
        MouseWheel="Window_MouseWheel" PreviewMouseWheel="Window_PreviewMouseWheel">

    <StackPanel MouseWheel="StackPanel_MouseWheel" PreviewMouseWheel="StackPanel_PreviewMouseWheel">
        <Label Content="Tiberius Julius Caesar Augustus" />
        <Button Content="Make Me Emperor" MouseWheel="Button_MouseWheel" PreviewMouseWheel="Button_PreviewMouseWheel"/>


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #676 – MouseWheel Event Is Fired for Element That Mouse Pointer Is Over

  1. Pingback: Dew Drop – October 25, 2012 (#1,429) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: