Home>

The background color is set only for the value part as shown below.
How can I set the background color to the part without the value (left of the numerical value)?

<DataGrid AutoGenerateColumns = "False" ItemsSource = "{Binding Data}">
    <DataGrid.Columns>
        <DataGridTextColumn Binding = "{Binding Value1}" Header = "Value 1">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType = "{x: Type TextBlock}">
                    <Setter Property = "HorizontalAlignment" Value = "Right" />
                    <Setter Property = "Background" Value = "YellowGreen" />
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

Thanks for your consideration.

  • Answer # 1

    What about below?

    <DataGridTextColumn Binding = "{Binding Value1}" Header = "Value 1">
        <DataGridTextColumn.ElementStyle>
            <Style TargetType = "{x: Type TextBlock}">
                <Setter Property = "HorizontalAlignment" Value = "Right" />
                <!-<Setter Property = "Background" Value = "YellowGreen" />->
            </Style>
        </DataGridTextColumn.ElementStyle>
        <DataGridTextColumn.CellStyle>
            <Style TargetType = "DataGridCell">
                <Setter Property = "Background" Value = "YellowGreen" />
            </Style>
        </DataGridTextColumn.CellStyle>
    </DataGridTextColumn>