如何自定义DataGrid标头? 这张照片显示了我想要做的事情......
我试试这个,但它不起作用......
<DataGridTemplateColumn.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Text="Název modelu"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" Text="Cena bez DPH"></TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" Text="Cena s DPH"></TextBlock>
</Grid>
</DataGridTemplateColumn.Header>
你能帮助我吗,我该怎么办?
答案 0 :(得分:1)
尝试在Center
TextBlock
<TextBlock HorizontalAlignment="Center"
Grid.Column="1" Grid.Row="1" Text="Cena s DPH"></TextBlock>
您可以从这里开始阅读有关WPF Layout system
的更多信息您还需要为HorizontalContentAlignment
DataGridColumnHeader
将其添加到DataGridTemplateColumn
:
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</DataGridTemplateColumn.HeaderStyle>
答案 1 :(得分:0)
尝试宽度=&#34; *&#34;在ColumnDefinitions上