Hello
I created a control that is very similar to http://xceed.com/CS/forums/thread/8224.aspx.
The 1st version of the control worked for pages with no hidden grids, but when these became visible not worked. (bad for me :()
this custom version works with all grids of the page, and when they become visible automatically adjust the columns (the trick is in the loaded because GetFittedWidth always return a valid value)
Any sugestions email-me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xceed.Wpf.DataGrid;
using System.Windows.Controls;
using System.Collections;
namespace etcetcetc.Grid
{
public class ctrGrid : Xceed.Wpf.DataGrid.DataGridControl
{
private bool RunAutoFit = false;
public ctrGrid()
: base()
{
this.Loaded += new System.Windows.RoutedEventHandler(ctrGrid_Loaded);
this.LayoutUpdated += new EventHandler(Grid_LayoutUpdated);
}
void ctrGrid_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
this.RunAutoFit = true;
Grid_LayoutUpdated(null, null);
}
private void Grid_LayoutUpdated(object sender, EventArgs e)
{
if (this.RunAutoFit && this.IsVisible)
{
AutoFit();
this.RunAutoFit = false;
}
}
public void AutoFit()
{
foreach (Column col in this.Columns)
{
double fittedWidth = col.GetFittedWidth();
if (fittedWidth > 0)
col.Width = fittedWidth + 2;
}
}
protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue)
{
UpdateLayout();
base.OnItemsSourceChanged(oldValue, newValue);
this.RunAutoFit = true;
}
}
}