Skip to content

Commit

Permalink
mouse scroll works in DataGrids (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylo-matov authored Sep 24, 2024
1 parent 17ae9e1 commit e5547c9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 47 deletions.
91 changes: 44 additions & 47 deletions TuneUp/TuneUpWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,20 @@
Grid.Column="0"
Grid.ColumnSpan="2">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel>
<!-- Latest Run -->
<TextBlock
Style="{StaticResource CollectionHeaderTextBlockStyle}"
Text="Latest run"
Visibility="{Binding LatestRunTableVisibility}" />
<DataGrid
x:Name="LatestRunTable"
AlternatingRowBackground="#434343"
ItemsSource="{Binding Path=ProfiledNodesCollectionLatestRun.View}"
MouseLeave="NodeAnalysisTable_MouseLeave"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
Sorting="LatestRunTable_Sorting"
Style="{StaticResource DataGridStyleTuneUpCombined}">
<StackPanel >
<!-- Latest Run -->
<TextBlock Text="Latest run"
Style="{StaticResource CollectionHeaderTextBlockStyle}"
Visibility="{Binding LatestRunTableVisibility}"/>
<DataGrid ItemsSource="{Binding Path=ProfiledNodesCollectionLatestRun.View}"
x:Name="LatestRunTable"
Style="{StaticResource DataGridStyleTuneUpCombined}"
AlternatingRowBackground="#434343"
Sorting="LatestRunTable_Sorting"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
MouseLeave="NodeAnalysisTable_MouseLeave"
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
<DataGrid.Columns>
<!-- Execution Order -->
<DataGridTextColumn Width="40" Header="#">
Expand Down Expand Up @@ -514,21 +513,20 @@
Style="{StaticResource CollectionFooterTextBlockStyle}"
Text="{Binding Path=LatestGraphExecutionTime, Mode=OneWay}" />
</StackPanel>
<!-- Previous Run -->
<TextBlock
Style="{StaticResource CollectionHeaderTextBlockStyle}"
Text="Previous run"
Visibility="{Binding PreviousRunTableVisibility}" />
<DataGrid
x:Name="PreviousRunTable"
AlternatingRowBackground="#434343"
HeadersVisibility="None"
ItemsSource="{Binding Path=ProfiledNodesCollectionPreviousRun.View}"
MouseLeave="NodeAnalysisTable_MouseLeave"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
Sorting="LatestRunTable_Sorting"
Style="{StaticResource DataGridStyleTuneUpCombined}">
<!-- Previous Run -->
<TextBlock Text="Previous run"
Style="{StaticResource CollectionHeaderTextBlockStyle}"
Visibility="{Binding PreviousRunTableVisibility}"/>
<DataGrid ItemsSource="{Binding Path=ProfiledNodesCollectionPreviousRun.View}"
x:Name="PreviousRunTable"
Style="{StaticResource DataGridStyleTuneUpCombined}"
AlternatingRowBackground="#434343"
HeadersVisibility="None"
Sorting="LatestRunTable_Sorting"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
MouseLeave="NodeAnalysisTable_MouseLeave"
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
<DataGrid.Columns>
<!-- Execution Order -->
<DataGridTextColumn Width="40" Binding="{Binding Converter={StaticResource ExecutionOrderNumberConverter}}">
Expand Down Expand Up @@ -570,23 +568,22 @@
Style="{StaticResource CollectionFooterTextBlockStyle}"
Text="{Binding Path=PreviousGraphExecutionTime, Mode=OneWay}" />
</StackPanel>
<!-- Not Executed -->
<TextBlock
Style="{StaticResource CollectionHeaderTextBlockStyle}"
Text="Not executed"
Visibility="{Binding NotExecutedTableVisibility}" />
<DataGrid
x:Name="NotExecutedTable"
AlternatingRowBackground="#434343"
AlternationCount="2"
CanUserSortColumns="False"
HeadersVisibility="None"
ItemsSource="{Binding Path=ProfiledNodesCollectionNotExecuted.View}"
MouseLeave="NodeAnalysisTable_MouseLeave"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
Sorting="NotExecutedTable_Sorting"
Style="{StaticResource DataGridStyleTuneUpCombined}">
<!-- Not Executed -->
<TextBlock Text="Not executed"
Style="{StaticResource CollectionHeaderTextBlockStyle}"
Visibility="{Binding NotExecutedTableVisibility}"/>
<DataGrid ItemsSource="{Binding Path=ProfiledNodesCollectionNotExecuted.View}"
x:Name="NotExecutedTable"
Style="{StaticResource DataGridStyleTuneUpCombined}"
AlternationCount="2"
AlternatingRowBackground="#434343"
HeadersVisibility="None"
CanUserSortColumns="False"
Sorting="NotExecutedTable_Sorting"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
MouseLeave="NodeAnalysisTable_MouseLeave"
PreviewMouseWheel="DataGrid_PreviewMouseWheel">
<DataGrid.Columns>
<!-- Execution Order -->
<DataGridTextColumn Width="40" />
Expand Down
42 changes: 42 additions & 0 deletions TuneUp/TuneUpWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,48 @@ private void NodeAnalysisTable_MouseLeave(object sender, System.Windows.Input.Mo
isUserInitiatedSelection = false;
}

/// <summary>
/// Forwards the mouse wheel scroll event from the DataGrid to the parent ScrollViewer,
/// enabling scrolling when the mouse is over the DataGrid.
/// </summary>
private void DataGrid_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
ScrollViewer scrollViewer = FindParent<ScrollViewer>((DataGrid)sender);

if (scrollViewer != null)
{
if (e.Delta > 0)
{
scrollViewer.LineUp();
}
else
{
scrollViewer.LineDown();
}

e.Handled = true;
}
}

/// <summary>
/// Recursively searches the visual tree to find the parent of the specified type T for a given child element.
/// </summary>
private T FindParent<T>(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<T>(parentObject);
}
}

private void RecomputeGraph_Click(object sender, RoutedEventArgs e)
{
(LatestRunTable.DataContext as TuneUpWindowViewModel).ResetProfiling();
Expand Down

0 comments on commit e5547c9

Please sign in to comment.