DataGrid列动态填充数据网格大小(DataGrid column Fill to Datagrid size Dynamically)
我有一个horizontally stretched的DataGrid包含one column 。 问题是DataGrid被拉伸但列保持不变。 我怎样才能填充DataGrid。 一切都是动态完成的,如何用代码完成。
var datagridDetails = new DataGrid { AutoGenerateColumns = false, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Stretch }; var columnDetails = new DataGridTextColumn { Header = "Details", CanUserSort = false, CanUserResize = false, Binding = new Binding("Details"), Width = StackPanelContent.ActualWidth/2 - 8 //hacking through it but not working quite well };I have a DataGrid which is horizontally stretched containing one column. the problem is the DataGrid gets streached but the column remains same. How can i make it fill the DataGrid. All is done Dynamically, how to do it with code.
var datagridDetails = new DataGrid { AutoGenerateColumns = false, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Stretch }; var columnDetails = new DataGridTextColumn { Header = "Details", CanUserSort = false, CanUserResize = false, Binding = new Binding("Details"), Width = StackPanelContent.ActualWidth/2 - 8 //hacking through it but not working quite well };最满意答案
在XAML中,这将是:
<DataGrid ColumnWidth = "*"/>要么
<DataGridTextColumn Width="*" />在实际的列定义上。
不知道如何在代码后面执行此操作。
编辑:
找到它,它将是:
var columnDetails = new DataGridTextColumn { Header = "Details", CanUserSort = false, CanUserResize = false, Binding = new Binding("Details"), Width = new DataGridLength(1.0, DataGridLengthUnitType.Star)};
In XAML this would be:
<DataGrid ColumnWidth = "*"/>or
<DataGridTextColumn Width="*" />On the actual column definition.
Not sure how to do this in code behind.
Edit:
Found it, it would be:
var columnDetails = new DataGridTextColumn { Header = "Details", CanUserSort = false, CanUserResize = false, Binding = new Binding("Details"), Width = new DataGridLength(1.0, DataGridLengthUnitType.Star)};
更多推荐
DataGrid,new,var,column,false,电脑培训,计算机培训,IT培训"/> <meta name="
发布评论