8
If you run the sample window below the upper ItemsControl will update layout for several seconds until finally all columns will have the correct width (correct = identical to the columns inside the lower ItemsControl).
You can change the width of the window and scroll the lower ItemsControls surrounding ScrollViewer both horizontally and vertically -- but as soon as you change the height of the Window the layout will flip for several seconds.
Note: There is no sizing ambiguity like in other questions where the grid infinitely updates sizes.
Is it me doing something wrong -- and if so, how could I fix this? -- or should I post this problem to Microsoft-Connect?
Code behind:
namespace DynamicGridColumnBinding
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
public partial class MainWindow
{
private static readonly CultureInfo[] cultureInfos =
CultureInfo.GetCultures(CultureTypes.NeutralCultures).Take(15).ToArray();
public MainWindow()
{
this.InitializeComponent();
}
public static IEnumerable<CultureInfo> AllCultures
{
get { return cultureInfos; }
}
private void GridInitialized(object sender, EventArgs e)
{
var grid = (Grid)sender;
for ( int i = 0; i < cultureInfos.Length; i++ )
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width = GridLength.Auto,
SharedSizeGroup = "g" + i,
});
}
private void ScrollViewerScrollChanged(object sender, ScrollChangedEventArgs e)
{
if ( e.HorizontalChange != 0 )
this.legendScroller.ScrollToHorizontalOffset(e.HorizontalOffset);
}
}
}