views:

318

answers:

3

The ScrollViewer's MouseWheel event will fire only when the scrollbar is at the end of it's track (either the top or bottom/left or right). The MouseWheel event does not fire when it's anywhere in between.

Does anyone have any clue as to how to capture the scrolling when it's being caused by the mouse wheel?

A: 

You need to add the following code to capture the scrolling event

public MainPage()
     {
      InitializeComponent();
      HtmlPage.Window.AttachEvent("DOMMouseScroll", OnMouseWheel);
      HtmlPage.Window.AttachEvent("onmousewheel", OnMouseWheel);
      HtmlPage.Document.AttachEvent("onmousewheel", OnMouseWheel);
      }

private void OnMouseWheel(object sender, HtmlEventArgs args)
      {
      // Your code goes here
      }

Reference : http://blog.thekieners.com/2009/04/06/how-to-enable-mouse-wheel-scrolling-in-silverlight-without-extending-controls/

To actually get the full scrolling working properly (without messing with mousewheel events), see my answer to this question - http://stackoverflow.com/questions/2986924/how-can-i-get-the-mouse-wheel-to-work-correctly-with-the-silverlight-4-scrollview

Chaitanya
I have no problem capturing the mouse wheel scrolling. My specific issue is that the scroll event does not fire until one of the two limits has been reached. Everything in between does not cause the mouse wheel to fire.
beaudetious
The code above fires on every mouse wheel scroll for me (in Firefox) not just when the thumb is at the limits.
Chaitanya
A: 

The scroll viewer is actually firing the event. The event is being handled, therefore, the handler will not be called. The way around this is to use the AddHandler method to add the handler.

Instead of using the UIElement.MouseWheel Event, use the UIElement.AddHandler method, like this:

MyScrollViewer.AddHandler(FrameworkElement.MouseWheelEvent,
    delegate(object sender, MouseWheelEventArgs e)
    {
        //if e.Handled == true then the page was actually scrolled,
        // otherwise, the scrollviewer is either at the beginning or at the end
        if (e.Handled == true)
        {
            //Here, you can do what you need
        }
    },
true);
Gabriel McAdams
A: 

@davidle1234:

    public delegate void SVMouseWheelDelegate(object sender, MouseWheelEventArgs e);
    public SVMouseWheelDelegate SVMouseWheelHandler { get; set; }

    private void SVMouseWheelHandlerLogic(object sender, MouseWheelEventArgs e)
    {
        //if e.Handled == true then the page was actually scrolled,
        // otherwise, the scrollviewer is either at the beginning or at the end
        if (e.Handled == true)
        {
            //Here, you can do what you need
        }
    }

and use it like so:

MyScrollViewer.AddHandler(FrameworkElement.MouseWheelEvent, SVMouseWheelHandler, true);
VoodooChild