我的DataGrid
horizontally stretched
包含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
};
答案 0 :(得分:1)
在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)
};