在 XAML 中有一个 datagridtemplate 列
<sdk:DataGridTemplateColumn x:Name="Urgency">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Image Source="{Binding UrgencyUri}"
VerticalAlignment="Stretch"
Stretch="UniformToFill"
Height="10" Width="10" Margin="0,0,5,0"/>
<TextBlock Text="{Binding Urgency}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTemplateColumn.HeaderStyle>
<Style TargetType="primitive:DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=Urgency, Source={StaticResource MHVWindowResources}}" Grid.Column="0" HorizontalAlignment="Left" />
<filter:DataGridColumnFilter Grid.Column="1" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</sdk:DataGridTemplateColumn.HeaderStyle>
</sdk:DataGridTemplateColumn>
我在下面使用了这段代码,但是它返回 null
DataGridTemplateColumn templateColumn = dataGrid.Columns[columnIndex] as DataGridTemplateColumn;
if (templateColumn != null)
{
string header = templateColumn.Header as string;
if (header == null)
{
return null;
}
bindingPath = header;
}
他们有什么我错过的吗?谢谢 我想知道如何在后面的代码中获取列标题。