How to add an image to a DataGridTemplateColumn header

冷暖自知 提交于 2019-12-11 18:25:01

问题


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>



来源:https://stackoverflow.com/questions/27942374/how-to-add-an-image-to-a-datagridtemplatecolumn-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!