-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(GH-356) Improve Package view
- Loading branch information
Showing
4 changed files
with
104 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Source/ChocolateyGui/Utilities/BubbleScrollEventBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright company="Chocolatey" file="BubbleScrollEventBehavior.cs"> | ||
// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using System.Windows; | ||
using System.Windows.Input; | ||
using System.Windows.Interactivity; | ||
|
||
namespace ChocolateyGui.Utilities | ||
{ | ||
/// <summary> | ||
/// The BubbleScrollEventBehavior 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 BubbleScrollEventBehavior : Behavior<UIElement> | ||
{ | ||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
|
||
AssociatedObject.PreviewMouseWheel -= AssociatedObject_PreviewMouseWheel; | ||
AssociatedObject.PreviewMouseWheel += AssociatedObject_PreviewMouseWheel; | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
AssociatedObject.PreviewMouseWheel -= AssociatedObject_PreviewMouseWheel; | ||
|
||
base.OnDetaching(); | ||
} | ||
|
||
private static void AssociatedObject_PreviewMouseWheel(object sender, MouseWheelEventArgs e) | ||
{ | ||
var uiElement = sender as UIElement; | ||
if (uiElement == null || Keyboard.IsKeyDown(Key.LeftShift)) | ||
{ | ||
return; | ||
} | ||
|
||
e.Handled = true; | ||
|
||
var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) { RoutedEvent = UIElement.MouseWheelEvent }; | ||
uiElement.RaiseEvent(e2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters