From e5547c945f04ae31688d290e19b6ad041625a35b Mon Sep 17 00:00:00 2001 From: Ivo Petrov <48355182+ivaylo-matov@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:14:44 +0100 Subject: [PATCH] mouse scroll works in DataGrids (#60) --- TuneUp/TuneUpWindow.xaml | 91 ++++++++++++++++++------------------- TuneUp/TuneUpWindow.xaml.cs | 42 +++++++++++++++++ 2 files changed, 86 insertions(+), 47 deletions(-) diff --git a/TuneUp/TuneUpWindow.xaml b/TuneUp/TuneUpWindow.xaml index f9599d3..3c6ae7f 100644 --- a/TuneUp/TuneUpWindow.xaml +++ b/TuneUp/TuneUpWindow.xaml @@ -454,21 +454,20 @@ Grid.Column="0" Grid.ColumnSpan="2"> - - - - + + + + @@ -514,21 +513,20 @@ Style="{StaticResource CollectionFooterTextBlockStyle}" Text="{Binding Path=LatestGraphExecutionTime, Mode=OneWay}" /> - - - + + + @@ -570,23 +568,22 @@ Style="{StaticResource CollectionFooterTextBlockStyle}" Text="{Binding Path=PreviousGraphExecutionTime, Mode=OneWay}" /> - - - + + + diff --git a/TuneUp/TuneUpWindow.xaml.cs b/TuneUp/TuneUpWindow.xaml.cs index 9cb571d..23b8a12 100644 --- a/TuneUp/TuneUpWindow.xaml.cs +++ b/TuneUp/TuneUpWindow.xaml.cs @@ -97,6 +97,48 @@ private void NodeAnalysisTable_MouseLeave(object sender, System.Windows.Input.Mo isUserInitiatedSelection = false; } + /// + /// Forwards the mouse wheel scroll event from the DataGrid to the parent ScrollViewer, + /// enabling scrolling when the mouse is over the DataGrid. + /// + private void DataGrid_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) + { + ScrollViewer scrollViewer = FindParent((DataGrid)sender); + + if (scrollViewer != null) + { + if (e.Delta > 0) + { + scrollViewer.LineUp(); + } + else + { + scrollViewer.LineDown(); + } + + e.Handled = true; + } + } + + /// + /// Recursively searches the visual tree to find the parent of the specified type T for a given child element. + /// + private T FindParent(DependencyObject child) where T : DependencyObject + { + DependencyObject parentObject = VisualTreeHelper.GetParent(child); + if (parentObject == null) return null; + + T parent = parentObject as T; + if (parent != null) + { + return parent; + } + else + { + return FindParent(parentObject); + } + } + private void RecomputeGraph_Click(object sender, RoutedEventArgs e) { (LatestRunTable.DataContext as TuneUpWindowViewModel).ResetProfiling();