我为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>
但它不起作用,似乎DataGrid不再有defaultStyle
,我认为问题是在上面的代码中为DataGridColumnHeader设置模板,但我该怎么办?
答案 0 :(得分:0)
好吧,我只需要设置ContentTemplate而不是Template !!
<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>