Fixed EditableListBoxControl mouse wheel scrolling

This commit is contained in:
Ben Wallis 2018-12-03 17:41:44 +00:00
parent a13dc44a7d
commit 6fb0ec8084
3 changed files with 37 additions and 0 deletions

@ -247,6 +247,7 @@
<Compile Include="UserControls\ThemeComponentSelectionControl.xaml.cs">
<DependentUpon>ThemeComponentSelectionControl.xaml</DependentUpon>
</Compile>
<Compile Include="Utility\VisualTreeUtility.cs" />
<Compile Include="ViewModels\DesignTime\DesignTimeItemFilterBlockViewModel.cs" />
<Compile Include="ViewModels\DesignTime\DesignTimeSettingsPageViewModel.cs" />
<Compile Include="Views\AttachedProperties\SelectedItemsAttachedProperty.cs" />

@ -0,0 +1,26 @@
using System.Windows;
using System.Windows.Media;
namespace Filtration.Utility
{
public class VisualTreeUtility
{
public static T FindParent<T>(DependencyObject child)
where T : DependencyObject
{
//get parent item
var parentObject = VisualTreeHelper.GetParent(child);
//we've reached the end of the tree
if (parentObject == null) return null;
//check if the parent matches the type we're looking for
if (parentObject is T parent)
{
return parent;
}
return FindParent<T>(parentObject);
}
}
}

@ -2,6 +2,8 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Filtration.UserControls;
using Filtration.Utility;
namespace Filtration.Views
{
@ -41,6 +43,14 @@ namespace Filtration.Views
// up and down in ItemFilterScriptView rather than within the block.
if (sender is ScrollViewer viewer && !e.Handled)
{
// Don't handle events if they originated from a control within an EditableListBoxControl
// since we still want to allow scrolling within those with the mouse wheel
if (e.OriginalSource is DependencyObject dependencyObject && VisualTreeUtility.FindParent<EditableListBoxControl>(dependencyObject) != null)
{
e.Handled = false;
return;
}
e.Handled = true;
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) {RoutedEvent = MouseWheelEvent, Source = viewer};