Skip to content

Commit 2581512

Browse files
authored
Merge pull request #5532 from MDoerner/SuppressHorizontalBringIntoViewInGroupinGrids
Suppress only horizontal scroll in inspection results window and test explorer
2 parents 8011485 + 4b01a60 commit 2581512

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
SelectionUnit="FullRow"
202202
ItemsSource="{Binding Results, NotifyOnSourceUpdated=True}"
203203
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
204+
RequestBringIntoView="InspectionResultsGrid_RequestBringIntoView"
204205
ScrollViewer.CanContentScroll="True"
205206
ScrollViewer.VerticalScrollBarVisibility="Auto"
206207
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1-
namespace Rubberduck.UI.Inspections
1+
using System.Windows;
2+
3+
namespace Rubberduck.UI.Inspections
24
{
35
/// <summary>
46
/// Interaction logic for InspectionResultsControl.xaml
57
/// </summary>
68
public partial class InspectionResultsControl
79
{
10+
private const int HorizontalRectangleAdjustment = 2000;
11+
812
private InspectionResultsViewModel ViewModel => DataContext as InspectionResultsViewModel;
913

1014
public InspectionResultsControl()
1115
{
1216
InitializeComponent();
1317
}
1418

15-
private void InspectionResultsGrid_RequestBringIntoView(object sender, System.Windows.RequestBringIntoViewEventArgs e)
19+
//Based on https://stackoverflow.com/a/42238409/5536802 by Jason Williams and the comment to it by Nick Desjardins.
20+
private bool _requestingModifiedBringIntoView;
21+
private void InspectionResultsGrid_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
1622
{
23+
if (_requestingModifiedBringIntoView
24+
|| !(e?.OriginalSource is FrameworkElement source))
25+
{
26+
return;
27+
}
28+
1729
e.Handled = true;
30+
31+
//Prevents adjustment of the adjusted event triggered below.
32+
_requestingModifiedBringIntoView = true;
33+
34+
var newRectangle = new Rect(-HorizontalRectangleAdjustment, 0, source.ActualWidth + HorizontalRectangleAdjustment, source.ActualHeight);
35+
source.BringIntoView(newRectangle);
36+
37+
_requestingModifiedBringIntoView = false;
1838
}
1939
}
2040
}

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
ShowGroupingItemCount="True"
335335
InitialExpandedState="True"
336336
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
337+
RequestBringIntoView="TestGrid_RequestBringIntoView"
337338
ScrollViewer.CanContentScroll="False"
338339
ScrollViewer.VerticalScrollBarVisibility="Auto"
339340
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
namespace Rubberduck.UI.UnitTesting
1+
using System.Windows;
2+
3+
namespace Rubberduck.UI.UnitTesting
24
{
35
/// <summary>
46
/// Interaction logic for TestExplorerControl.xaml
57
/// </summary>
68
public partial class TestExplorerControl
79
{
10+
private const int HorizontalRectangleAdjustment = 2000;
11+
812
public TestExplorerControl()
913
{
1014
InitializeComponent();
1115
}
1216

13-
private void TestGrid_RequestBringIntoView(object sender, System.Windows.RequestBringIntoViewEventArgs e)
17+
//Based on https://stackoverflow.com/a/42238409/5536802 by Jason Williams and the comment to it by Nick Desjardins.
18+
private bool _requestingModifiedBringIntoView;
19+
private void TestGrid_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
1420
{
21+
if (_requestingModifiedBringIntoView
22+
|| !(e?.OriginalSource is FrameworkElement source))
23+
{
24+
return;
25+
}
26+
1527
e.Handled = true;
28+
29+
//Prevents adjustment of the adjusted event triggered below.
30+
_requestingModifiedBringIntoView = true;
31+
32+
var newRectangle = new Rect(-HorizontalRectangleAdjustment, 0, source.ActualWidth + HorizontalRectangleAdjustment, source.ActualHeight);
33+
source.BringIntoView(newRectangle);
34+
35+
_requestingModifiedBringIntoView = false;
1636
}
1737
}
1838
}

0 commit comments

Comments
 (0)