XAML WPF DataGrid: reduce columns width to fit its content while scrolling except one

Here is the solution to automatically reduce DataGrid columns width during scrolling. I need a slightly modified version where last column fills all row width left after other columns.

The old solution:

private void OnLoadingRow(object sender, DataGridRowEventArgs e)
{
    if (sender is not DataGrid dg) return;
    foreach (var c in dg.Columns) c.Width = 0;
    e.Row.UpdateLayout();
    foreach (var c in dg.Columns) c.Width = DataGridLength.Auto;
}

If dg.Columns.Last().Width = new DataGridLength(1, DataGridLengthUnitType.Star); added at the end of the method last column not respects other columns Auto size and forces its size to 20px (see the pic). enter image description here



from Recent Questions - Stack Overflow https://ift.tt/3rcmWQO
https://ift.tt/3rl40zD

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations