How do I make XAML DataGridColumns fill the entire

2019-01-17 05:28发布

I am using DataGrids in XAML (not Silverlight) with resizable columns, the DataGrid will expand if the user resizes the screen.

Currently if the widths of all the DataGrid columns are less than the width of the DataGrid I get an extra "column" appearing which is unclickable and serves no purpose.

Does anyone know how to make one column always resize to fill all the remaining space?

9条回答
趁早两清
2楼-- · 2019-01-17 05:59

Another spin on the same theme:

protected void OnWindowSizeChanged(object sender, SizeChangedEventArgs e)
    {
        dataGrid.Width = e.NewSize.Width - (e.NewSize.Width * .1);

        foreach (var column in dataGrid.Columns)
        {
            column.Width = dataGrid.Width / dataGrid.Columns.Count;
        }

    }
查看更多
对你真心纯属浪费
3楼-- · 2019-01-17 06:01

set ONE column's width to any value, i.e. width="*"

查看更多
The star\"
4楼-- · 2019-01-17 06:02

Make sure your DataGrid has Width set to something like {Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window,AncestorLevel=1}}.

Like that, your setting of Width="*" attribute on DataGrid.Columns/DataGridXXXXColumn elements should work.

查看更多
登录 后发表回答