Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Interactivity;
- namespace ExtraBehaviors
- {
- /// <summary>
- /// The BubbleScrollEvent behavior can be used to prevent the mousewheel scrolling on a scrollable control.
- /// The event will be bubble up to the parent control.
- /// This behavior can be prevent with the left Shift key.
- /// </summary>
- public class BubbleScrollEvent : Behavior<UIElement>
- {
- protected override void OnAttached() {
- base.OnAttached();
- this.AssociatedObject.PreviewMouseWheel -= this.AssociatedObject_PreviewMouseWheel;
- this.AssociatedObject.PreviewMouseWheel += this.AssociatedObject_PreviewMouseWheel;
- }
- protected override void OnDetaching() {
- this.AssociatedObject.PreviewMouseWheel -= this.AssociatedObject_PreviewMouseWheel;
- base.OnDetaching();
- }
- void AssociatedObject_PreviewMouseWheel(object sender, MouseWheelEventArgs e) {
- if (!Keyboard.IsKeyDown(Key.LeftShift)) {
- e.Handled = true;
- var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) {RoutedEvent = UIElement.MouseWheelEvent};
- this.AssociatedObject.RaiseEvent(e2);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment