ExtendedScrollViewer.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Windows.Controls;
  2. using System.Windows.Input;
  3. namespace MediaBrowser.UI.Controls
  4. {
  5. /// <summary>
  6. /// This subclass solves the problem of ScrollViewers eating KeyDown for all arrow keys
  7. /// </summary>
  8. public class ExtendedScrollViewer : ScrollViewer
  9. {
  10. protected override void OnKeyDown(KeyEventArgs e)
  11. {
  12. if (e.Handled || e.OriginalSource == this)
  13. {
  14. base.OnKeyDown(e);
  15. return;
  16. }
  17. // Don't eat left/right if horizontal scrolling is disabled
  18. if (e.Key == Key.Left || e.Key == Key.Right)
  19. {
  20. if (HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled)
  21. {
  22. return;
  23. }
  24. }
  25. // Don't eat up/down if vertical scrolling is disabled
  26. if (e.Key == Key.Up || e.Key == Key.Down)
  27. {
  28. if (VerticalScrollBarVisibility == ScrollBarVisibility.Disabled)
  29. {
  30. return;
  31. }
  32. }
  33. // Let the base class do it's thing
  34. base.OnKeyDown(e);
  35. }
  36. }
  37. }