@@ -312,6 +312,46 @@ public void Does_Not_Realize_Columns_Outside_Viewport()
312
312
Assert . True ( double . IsNaN ( columns [ 3 ] . ActualWidth ) ) ;
313
313
}
314
314
315
+ [ AvaloniaFact ( Timeout = 10000 ) ]
316
+ public void Columns_Are_Correctly_Sized_After_Changing_Source ( )
317
+ {
318
+ // Create the initial target with 2 columns and make sure our preconditions are correct.
319
+ var ( target , items ) = CreateTarget ( columns : new IColumn < Model > [ ]
320
+ {
321
+ new TextColumn < Model , int > ( "ID" , x => x . Id , width : new GridLength ( 1 , GridUnitType . Star ) ) ,
322
+ new TextColumn < Model , string ? > ( "Title1" , x => x . Title , options : MinWidth ( 50 ) ) ,
323
+ } ) ;
324
+
325
+ AssertColumnIndexes ( target , 0 , 2 ) ;
326
+
327
+ // Create a new source and assign it to the TreeDataGrid.
328
+ var newSource = new FlatTreeDataGridSource < Model > ( items )
329
+ {
330
+ Columns =
331
+ {
332
+ new TextColumn < Model , int > ( "ID" , x => x . Id , width : new GridLength ( 1 , GridUnitType . Star ) ) ,
333
+ new TextColumn < Model , string ? > ( "Title1" , x => x . Title , options : MinWidth ( 20 ) ) ,
334
+ new TextColumn < Model , string ? > ( "Title2" , x => x . Title , options : MinWidth ( 20 ) ) ,
335
+ }
336
+ } ;
337
+
338
+ target . Source = newSource ;
339
+
340
+ // The columns should not have an ActualWidth yet.
341
+ Assert . True ( double . IsNaN ( newSource . Columns [ 0 ] . ActualWidth ) ) ;
342
+ Assert . True ( double . IsNaN ( newSource . Columns [ 1 ] . ActualWidth ) ) ;
343
+ Assert . True ( double . IsNaN ( newSource . Columns [ 2 ] . ActualWidth ) ) ;
344
+
345
+ // Do a layout pass and check that the columns have been correctly sized.
346
+ target . UpdateLayout ( ) ;
347
+ AssertColumnIndexes ( target , 0 , 3 ) ;
348
+
349
+ var columns = ( ColumnList < Model > ) target . Columns ! ;
350
+ Assert . Equal ( 60 , columns [ 0 ] . ActualWidth ) ;
351
+ Assert . Equal ( 20 , columns [ 1 ] . ActualWidth ) ;
352
+ Assert . Equal ( 20 , columns [ 2 ] . ActualWidth ) ;
353
+ }
354
+
315
355
public class RemoveItems
316
356
{
317
357
[ AvaloniaFact ( Timeout = 10000 ) ]
0 commit comments