did not make any sense for me, sorry.
I understand the code, but this part:
Column widths shrink to fit correctly when increasing in column size but do
not properly shrink to fit when decreasing in column size. It will not
decrase the size of the column on an ItemsSource update after it has increased
has me puzzled
I understood this like that:
if the width of a column's content increases, the column's width increases, but if the
content's width decreases, the column's width does not.
Is that right ?
if so, this behaviour is normal: Wpf will just resize a datagrid's column width set to Auto if needed, i.e: the content cannot be displayed entirely. So when the content's width shrinks, the column does not resize as the content can still been seen entirely.
the only way I can see to force wpf to recalculate the columns' widths would be to force them all to 0 and then back to auto in the code behind, with one or two updateLayout() thrown in, but this is not very nice programming :-/
Edit:
basically, in your code behind:
foreach (DataGridColumn c in dg.Columns)
c.Width = 0;
// Update your DG's source here
foreach (DataGridColumn c in dg.Columns)
c.Width = DataGridLength.Auto;
and you probably need a dg.UpdateLayout() or two somewhere in there (after the update and the setting back to auto probably)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…