我已经为DataGridColumnHeader做了一个stlye,我想从默认的DataGridColumnHeader派生它,所以我这样做:
<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="ColumnHeaderStyle" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<TextBlock Grid.Column="1" Grid.Row="0" Text="{TemplateBinding Content}" HorizontalAlignment="Center">
</TextBlock>
......
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
但它不起作用,似乎数据网格不再具有defaultStyle
,我认为问题是在上面的代码中为 DataGridColumnHeader 设置模板,但我该怎么办?
好吧,我只需要设置内容模板而不是模板!!
<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="ColumnHeaderStyle" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<TextBlock Grid.Column="1" Grid.Row="0" Text="{TemplateBinding Content}" HorizontalAlignment="Center">
</TextBlock>
......
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>