3

Here's my code:

    public AbilitiesController(Abilities page)
    {
        _page = page;
        page.ScrollBar.MouseLeftButtonDown += MouseDown;
        page.ScrollBar.MouseLeftButtonUp += MouseUp;
        page.ScrollBar.MouseLeave += MouseLeave;
        page.ScrollBar.MouseWheel += MouseWheel;
        page.ScrollBar.MouseMove += MouseMove;
    }

    private void MouseMove(object sender, MouseEventArgs mouseEventArgs)
    {
        if (!_dragBound) return;
        var newPos = mouseEventArgs.GetPosition(_page);
        var dPos = newPos - _pos;
        _page.ScrollBar.ScrollToHorizontalOffset(dPos.X);
        _page.ScrollBar.ScrollToVerticalOffset(dPos.Y);
        _pos = newPos;
        Console.WriteLine("Moved");
    }

    private void MouseWheel(object sender, MouseWheelEventArgs mouseWheelEventArgs)
    {
        Console.WriteLine("MouseWheel");
    }

    private void MouseLeave(object sender, MouseEventArgs mouseEventArgs)
    {
        _dragBound = false;
        Console.WriteLine("Left");
    }

    private void MouseUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
    {
        _dragBound = false;
        Console.WriteLine("Mouse Up");
    }

    private void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
    {
        _dragBound = true;
        Console.WriteLine("Click!");
    }

Page is a Page, Scrollbar is a Scrollview.

I know my logic for moving the scrollbar probably isn't correct yet, but we aren't even getting that far yet.

For some odd reason the MouseDown event isn't firing whether I bind it to MouseDown or MouseLeftButtonDown.

However oddly enough the MouseUp event works no problem.

Which seems really odd because normally if one is broken, the other is too...

Using latest version of Visual Studio 2017 in a WPF project.

svick
  • 236,525
  • 50
  • 385
  • 514
  • according to this post, it's likely mouse down has been overriden by the ScrollBar class already. http://stackoverflow.com/questions/22813608/wpf-button-mouseleftbuttondown-doesnt-work-at-all – chris-crush-code Apr 25 '17 at 19:20
  • Tried binding to page.MouseDown and page.MouseUp, still the exact same problem. – Steffen Cole Blake Apr 25 '17 at 19:21
  • what about throwing an override on it. Just a guess but that would work if it's been overridden in some base class. – chris-crush-code Apr 25 '17 at 19:44
  • See this: http://stackoverflow.com/questions/16100027/wpf-canvas-swallowing-mousedownevent .... use Focusable="False" on your ScrollViewer – Colin Smith Apr 25 '17 at 20:46

1 Answers1

2

You might want to try 'PreviewMouseDown' instead of 'MouseDown' and same for all the other non-working mouse events, as they may already be being handled by whatever the base class of your 'Abilities' class is.

Curtis
  • 5,794
  • 8
  • 50
  • 77