How to add an image to a DataGridTemplateColumn he

2019-09-09 20:31发布

问题:

I have a Datagrid with some DataGridTemplateColumns. One of them is for the costs (see code below). The column heading is Costs. Now I want a image at the right side of the heading Costs. How can I do that?

<DataGrid     
        ItemsSource="{Binding AvailableNetworkInterfaces}"   
        SelectedItem="{Binding SelectedItemProperty}">

    <DataGrid.Columns>

    <DataGridTemplateColumn Header="Costs" Width="100" x:Name="ColumnCosts">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBox Width="80" Text="{Binding Dollar, Mode=OneWay}"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>

    </DataGrid.Columns>
</DataGrid>

回答1:

<DataGrid     
    ItemsSource="{Binding AvailableNetworkInterfaces}"   
    SelectedItem="{Binding SelectedItemProperty}">

<DataGrid.Columns>

<DataGridTemplateColumn Width="100" x:Name="ColumnCosts">
    <DataGridTemplateColumn.Header>
       <Stackpanel>
          <TextBlock Text="Costs"/>
          <Image Source="...\" />
       </Stackpanel>
    </DataGridTemplateColumn.Header
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBox Width="80" Text="{Binding Dollar, Mode=OneWay}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

</DataGrid.Columns>