当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - WPF DataGrid apply style for ColumnWidth with * does not work

问题描述:

I tried to apply style for DataGrid globally as followed:

<Style TargetType="DataGrid">

<Setter Property="ColumnWidth" Value="*"/>

<Setter Property="RowHeaderWidth" Value="0"/>

</Style>

The style for RowHeaderWidth works but the style for ColumnWidth does not (there is empty column at the end of the DataGrid). When I set ColumnWidth="*" explicitly in the DataGrid, then it works (the empty column has gone).

I wonder if we are able to set ColumnWidth="*" globally in the Style? Thank you in advance!

网友答案:

In the project I'm working on, we make a lot of own controls that are in a ResourceDictionary. We use the same exact method that you do. So, is your Style tag in a ResourceDictionary?

网友答案:

DataGrid.ColumnWidth cannot be applied style as other properties. We have to assign the value explicitly

分享给朋友:
您可能感兴趣的文章:
随机阅读: