kay00
kay00

Reputation: 447

WPF: DataGridCell override the row style color

I have a datagrid. I want one of the column's background to be a different color. I want the cell background to be completely darkblue or black. Not a combination of red + black or red+darkblue. Is there something I can do to override the row color for a particular column?

<ResourceDictionary> 
<Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Side}" Value="SELL">
                    <Setter Property="Background" Value="Red"></Setter>
                    <Setter Property="Foreground" Value="White"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>

    <Style x:Key="ColumnBeThisColor" TargetType="{x:Type DataGridCell}">
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="Background" Value="Black"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding ColumnA}" Value="True">
                <Setter Property="Background" Value="DarkBlue" />
                <Setter Property="Foreground" Value="White" />
            </DataTrigger>
            <DataTrigger Binding="{Binding ColumnA}" Value="False">
                <Setter Property="Background" Value="Black" />
                <Setter Property="Foreground" Value="White" />
            </DataTrigger>           
        </Style.Triggers>
    </Style>
</ResourceDictionary>



<DataGridTextColumn Header="ColumnOneColor" CellStyle="{StaticResource ColumnBeThisColor}" Width="60" Binding="{Binding Path=ThisColumn}"/>

This is good.But the text is not alight to the right enter image description here

This is align to the right, but the background is not completely black enter image description here

Also - how do I not have the red border?

Upvotes: 1

Views: 893

Answers (1)

kay00
kay00

Reputation: 447

I have a style that targettype is datagridcell. I have another style where the targettype is textblock. I set cellstyle and elementstyle accordingly.

Upvotes: 1

Related Questions