2
0

ExtendedButton.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. namespace MediaBrowser.UI.Controls
  5. {
  6. /// <summary>
  7. /// This subclass simply autofocuses itself when the mouse moves over it
  8. /// </summary>
  9. public class ExtendedButton : Button
  10. {
  11. private Point? _lastMouseMovePoint;
  12. /// <summary>
  13. /// Handles OnMouseMove to auto-select the item that's being moused over
  14. /// </summary>
  15. protected override void OnMouseMove(MouseEventArgs e)
  16. {
  17. base.OnMouseMove(e);
  18. var window = this.GetWindow();
  19. // If the cursor is currently hidden, don't bother reacting to it
  20. if (Cursor == Cursors.None || window.Cursor == Cursors.None)
  21. {
  22. return;
  23. }
  24. // Store the last position for comparison purposes
  25. // Even if the mouse is not moving this event will fire as elements are showing and hiding
  26. var pos = e.GetPosition(window);
  27. if (!_lastMouseMovePoint.HasValue)
  28. {
  29. _lastMouseMovePoint = pos;
  30. return;
  31. }
  32. if (pos == _lastMouseMovePoint)
  33. {
  34. return;
  35. }
  36. _lastMouseMovePoint = pos;
  37. Focus();
  38. }
  39. }
  40. }