Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Below is the behavior I am using. And below that is how you attach it to the datagrid in xaml.</p> <pre><code>using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Automation.Peers; using System.Windows.Interactivity; using System.Windows.Automation.Provider; using System.Windows.Automation; using System.Windows.Data; namespace GLS.Gui.Helper.Behaviors { public class MouseWheelScrollBehavior : Behavior&lt;Control&gt; { /// &lt;summary&gt; /// Gets or sets the peer. /// &lt;/summary&gt; /// &lt;value&gt;The peer.&lt;/value&gt; private AutomationPeer Peer { get; set; } /// &lt;summary&gt; /// Called after the behavior is attached to an AssociatedObject. /// &lt;/summary&gt; /// &lt;remarks&gt;Override this to hook up functionality to the AssociatedObject.&lt;/remarks&gt; protected override void OnAttached() { this.Peer = FrameworkElementAutomationPeer.FromElement(this.AssociatedObject); if (this.Peer == null) this.Peer = FrameworkElementAutomationPeer.CreatePeerForElement(this.AssociatedObject); this.AssociatedObject.MouseWheel += new MouseWheelEventHandler(AssociatedObject_MouseWheel); base.OnAttached(); } /// &lt;summary&gt; /// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred. /// &lt;/summary&gt; /// &lt;remarks&gt;Override this to unhook functionality from the AssociatedObject.&lt;/remarks&gt; protected override void OnDetaching() { this.AssociatedObject.MouseWheel -= new MouseWheelEventHandler(AssociatedObject_MouseWheel); base.OnDetaching(); } /// &lt;summary&gt; /// Handles the MouseWheel event of the AssociatedObject control. /// &lt;/summary&gt; /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt; /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Input.MouseWheelEventArgs"/&gt; instance containing the event data.&lt;/param&gt; void AssociatedObject_MouseWheel(object sender, MouseWheelEventArgs e) { //Do not handle already handled events if (e.Handled) return; this.AssociatedObject.Focus(); int direction = Math.Sign(e.Delta); ScrollAmount scrollAmount = (direction &lt; 0) ? ScrollAmount.SmallIncrement : ScrollAmount.SmallDecrement; if (this.Peer != null) { IScrollProvider scrollProvider = this.Peer.GetPattern(PatternInterface.Scroll) as IScrollProvider; bool shiftKey = (Keyboard.Modifiers &amp; ModifierKeys.Shift) == ModifierKeys.Shift; if (scrollProvider != null &amp;&amp; scrollProvider.VerticallyScrollable &amp;&amp; !shiftKey) { scrollProvider.Scroll(ScrollAmount.NoAmount, scrollAmount); e.Handled = true; } else if (scrollProvider != null &amp;&amp; scrollProvider.VerticallyScrollable &amp;&amp; shiftKey) { scrollProvider.Scroll(scrollAmount, ScrollAmount.NoAmount); e.Handled = true; } } } } } </code></pre> <p>How to attach the behavior: </p> <pre><code>&lt;data:DataGrid&gt; &lt;i:Interaction.Behaviors&gt; &lt;b:MouseWheelScrollBehavior /&gt; &lt;/i:Interaction.Behaviors&gt; &lt;/data:DataGrid&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload