@@ -43,6 +43,51 @@ public PackageManagerTopPanel()
4343 var cvs = Resources [ "cvsPackageSources" ] as CollectionViewSource ;
4444 cvs . Culture = CultureInfo . DefaultThreadCurrentUICulture ;
4545 cvs . Source = PackageSources ;
46+
47+ // Hook Loaded so we can measure hidden text measurers and set column MaxWidth.
48+ Loaded += PackageManagerTopPanel_Loaded ;
49+ }
50+
51+ private void PackageManagerTopPanel_Loaded ( object sender , RoutedEventArgs e )
52+ {
53+ // Perform an immediate measurement to initialize column widths.
54+ UpdateMeasuredColumnWidths ( ) ;
55+ }
56+
57+ private void UpdateMeasuredColumnWidths ( )
58+ {
59+ try
60+ {
61+ if ( _measurerPrerelease == null || _measurerVulnerabilities == null || _checkboxPrerelease == null )
62+ {
63+ return ;
64+ }
65+
66+ // Measure the hidden TextBlocks with infinite available width so they compute their natural width.
67+ _measurerPrerelease . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
68+ _measurerVulnerabilities . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
69+
70+ double w1 = _measurerPrerelease . DesiredSize . Width ;
71+ double w2 = _measurerVulnerabilities . DesiredSize . Width ;
72+
73+ // Add some slack to account for the checkbox glyph and margins.
74+ const double extra = 28.0 ;
75+
76+ var parentGrid = _checkboxPrerelease . Parent as Grid ;
77+ if ( parentGrid != null && parentGrid . ColumnDefinitions . Count > 3 )
78+ {
79+ parentGrid . ColumnDefinitions [ 2 ] . MaxWidth = w1 + extra ;
80+ parentGrid . ColumnDefinitions [ 3 ] . MaxWidth = w2 + extra ;
81+ }
82+ }
83+ catch ( InvalidOperationException )
84+ {
85+ // Swallow exceptions from layout/measure to avoid breaking UI initialization.
86+ }
87+ catch ( ArgumentException )
88+ {
89+ // Swallow exceptions from layout/measure to avoid breaking UI initialization.
90+ }
4691 }
4792
4893 public void CreateAndAddConsolidateTab ( )
0 commit comments