didn't make any sense to me, sorry.
I understand the code, but this part:
Column widths are compressed for proper installation when increasing the size of the column, but do not clean properly when reducing the size of the column. I will not reduce the size of the column in updating the ItemsSource after it has increased
puzzles me
I understood it like this:
if the width of the contents of the column increases, the width of the column increases, but if the width of the contents decreases, the width of the column is absent.
Is it correct?
If so, this is normal: Wpf will just resize the datagrid column set to Auto if necessary, i.e. content cannot be fully displayed. Therefore, when the width of the content decreases, the column does not change, because the content can still be seen completely.
the only way wpf recalculates the width of the columns would be to make them all equal to 0, and then return to the auto in the code behind, with one or two updateLayout () that were introduced, but this is not very nice programming: - /
Edit: basically, in your code:
foreach (DataGridColumn c in dg.Columns) c.Width = 0;
and you probably need dg.UpdateLayout () or two where it is (after the update and installation return to the car, probably)
David source share