Skip to content

Commit 16d72d6

Browse files
committed
Added events and code to copy column widths when switching between grouping grids on TestExplorerControl form
1 parent 7aca5e1 commit 16d72d6

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@
626626
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByOutcome}}"
627627
SelectedItem="{Binding SelectedTest}"
628628
ShowGroupingItemCount="True"
629-
Visibility="{Binding GroupByOutcome, Converter={StaticResource BoolToVisibility}}">
629+
Visibility="{Binding GroupByOutcome, Converter={StaticResource BoolToVisibility}}"
630+
IsVisibleChanged="ResultsGroupingGrid_IsVisibleChanged">
630631
<DataGrid.Columns>
631632
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Outcome}">
632633
<DataGridTemplateColumn.CellTemplate>
@@ -645,7 +646,8 @@
645646
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByModule}}"
646647
SelectedItem="{Binding SelectedTest}"
647648
ShowGroupingItemCount="True"
648-
Visibility="{Binding GroupByLocation, Converter={StaticResource BoolToVisibility}}">
649+
Visibility="{Binding GroupByLocation, Converter={StaticResource BoolToVisibility}}"
650+
IsVisibleChanged="ResultsGroupingGrid_IsVisibleChanged">
649651
<DataGrid.Columns>
650652
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Outcome}">
651653
<DataGridTemplateColumn.CellTemplate>
@@ -664,7 +666,8 @@
664666
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByCategory}}"
665667
SelectedItem="{Binding SelectedTest}"
666668
ShowGroupingItemCount="True"
667-
Visibility="{Binding GroupByCategory, Converter={StaticResource BoolToVisibility}}">
669+
Visibility="{Binding GroupByCategory, Converter={StaticResource BoolToVisibility}}"
670+
IsVisibleChanged="ResultsGroupingGrid_IsVisibleChanged">
668671
<DataGrid.Columns>
669672
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Outcome}">
670673
<DataGridTemplateColumn.CellTemplate>

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Windows.Data;
33
using System.Windows.Threading;
4+
using Rubberduck.UI.Controls;
45

56
namespace Rubberduck.UI.UnitTesting
67
{
@@ -68,5 +69,31 @@ protected virtual void Dispose(bool disposing)
6869
DataContextChanged -= TestExplorerControl_DataContextChanged;
6970
_isDisposed = true;
7071
}
72+
private GroupingGrid _newGroupingGrid;
73+
private void ResultsGroupingGrid_IsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
74+
{
75+
if (sender is GroupingGrid)
76+
{
77+
GroupingGrid groupingGrid = (GroupingGrid)sender;
78+
// actual height checks that form is visible at this point
79+
// don't set up the "new" visible element until we see an object with an actual height
80+
if (!((groupingGrid.ActualHeight == 0) && (_newGroupingGrid is null))) // check form elements are actually set up (i.e. not initialising form)
81+
{
82+
// this code relies on the new element being made visible before the old is hidden, so we save the new element
83+
// and then copy column widths from the old now hidden element on the subsequent invocation
84+
if (groupingGrid.IsVisible)
85+
_newGroupingGrid = groupingGrid;
86+
else
87+
{
88+
// copy column widths from previously visible grouping grid to ensure widths are consistent
89+
for (int columnIndex = 0; columnIndex < groupingGrid.Columns.Count; columnIndex++)
90+
{
91+
// copy column widths from current now hidden columns to the new visible columns
92+
_newGroupingGrid.Columns[columnIndex].Width = groupingGrid.Columns[columnIndex].Width;
93+
}
94+
}
95+
}
96+
}
97+
}
7198
}
7299
}

0 commit comments

Comments
 (0)