Skip to content

Commit

Permalink
Fixes scrolling of RibbonTabControl if focus/mouse is outside of it
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Feb 15, 2018
1 parent 1d74393 commit 176eee0
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions Fluent.Ribbon/Controls/RibbonTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Fluent
using System.Windows.Input;
using System.Windows.Media;
using ControlzEx.Standard;
using Fluent.Internal;
using Fluent.Internal.KnownBoxes;

/// <summary>
Expand Down Expand Up @@ -597,23 +598,6 @@ protected override void OnKeyDown(KeyEventArgs e)

#region Private methods

private static bool IsRibbonGroupBoxAncestorOf(DependencyObject element)
{
while (element != null)
{
if (element is RibbonGroupBox)
{
return true;
}

var parent = LogicalTreeHelper.GetParent(element) ?? VisualTreeHelper.GetParent(element);

element = parent;
}

return false;
}

// Process mouse wheel event
internal void ProcessMouseWheel(MouseWheelEventArgs e)
{
Expand All @@ -624,10 +608,16 @@ internal void ProcessMouseWheel(MouseWheelEventArgs e)
}

var focusedElement = Keyboard.FocusedElement as DependencyObject;

// Prevent scrolling if any control inside a RibbonGroupBox has focus
if (focusedElement != null
&& IsRibbonGroupBoxAncestorOf(focusedElement))
var originalSource = e.OriginalSource as DependencyObject;

// Prevent scrolling if
// - any control inside a RibbonGroupBox has focus
// - any control outside this RibbonTabControl caused the mouse wheel event
if ((focusedElement != null
&& UIHelper.GetParent<RibbonGroupBox>(focusedElement) != null)
||
(originalSource != null
&& UIHelper.GetParent<RibbonTabControl>(originalSource) == null))
{
return;
}
Expand Down

0 comments on commit 176eee0

Please sign in to comment.