Scroll Wheel Bug

Dec 28, 2010 at 10:00 PM

Noticed that the mouse scroll wheel was not working so I took a peek. I don't have a clue about contributing changes in CodePlex so I figured I'd post the fix here.

In SilverlightWindowless, the SendScroll method should be:

public void SendScroll( int amount, double relativeX, double relativeY )

    var p = GetAbsolutePoint( relativeX, relativeY );

    var lparam = MakeLParam( p.x, p.y );
    var wparam = MakeLParam( 0, amount );

    if (InvokeRequired)
        PostMessage(HWND, WindowsMessages.WM_MOUSEWHEEL, wparam, lparam);
        SendMessage(HWND, WindowsMessages.WM_MOUSEWHEEL, wparam, lparam);

In SilverlightViewPortElement, the OnMouseWheel method should be:

protected override void OnMouseWheel(MouseWheelEventArgs e)

    Point p = e.GetPosition( this );
    p.X = p.X / ActualWidth;
    p.Y = p.Y / ActualHeight;

    if(m_silverlightWindowless != null)
        m_silverlightWindowless.BeginInvoke((Action)(() => m_silverlightWindowless.SendScroll(e.Delta, p.X, p.Y)));