Guest User

Untitled

a guest
Sep 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using System.Windows;
  2. using System.Windows.Input;
  3. using System.Windows.Interactivity;
  4.  
  5. namespace ExtraBehaviors
  6. {
  7. /// <summary>
  8. /// The BubbleScrollEvent behavior can be used to prevent the mousewheel scrolling on a scrollable control.
  9. /// The event will be bubble up to the parent control.
  10. /// This behavior can be prevent with the left Shift key.
  11. /// </summary>
  12. public class BubbleScrollEvent : Behavior<UIElement>
  13. {
  14. protected override void OnAttached() {
  15. base.OnAttached();
  16. this.AssociatedObject.PreviewMouseWheel -= this.AssociatedObject_PreviewMouseWheel;
  17. this.AssociatedObject.PreviewMouseWheel += this.AssociatedObject_PreviewMouseWheel;
  18. }
  19.  
  20. protected override void OnDetaching() {
  21. this.AssociatedObject.PreviewMouseWheel -= this.AssociatedObject_PreviewMouseWheel;
  22. base.OnDetaching();
  23. }
  24.  
  25. void AssociatedObject_PreviewMouseWheel(object sender, MouseWheelEventArgs e) {
  26. if (!Keyboard.IsKeyDown(Key.LeftShift)) {
  27. e.Handled = true;
  28. var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) {RoutedEvent = UIElement.MouseWheelEvent};
  29. this.AssociatedObject.RaiseEvent(e2);
  30. }
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment