简体   繁体   English

在WPF的第一列上设置固定的GridView宽度

[英]Setting a fixed GridView width on the first column in WPF

I have a GridView that is connected to a Dictionary<>. 我有一个连接到Dictionary <>的GridView。 I want to set a maximum width only for the first column. 我只想为第一列设置最大宽度。 I know that DataGrid.ColumnWidth sets a static columnwidth, but that's for all the columns. 我知道DataGrid.ColumnWidth设置了一个静态的columnwidth,但这适用于所有列。 How can I define specific width for specific columns? 如何为特定的列定义特定的宽度?

网格视图

You can use DataGridTemplateColumn template: 您可以使用DataGridTemplateColumn模板:

`<DataGrid.Columns>
   <DataGridTemplateColumn Width="300" Header="Test">
//Your control (TextBlock)
   </DataGridTemplateColumn>
</DataGrid.Columns>`

找到了答案:

DataGrid.Columns[0].Width = 150;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM