简体   繁体   中英

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 在此处输入图片说明

This is align to the right, but the background is not completely black 在此处输入图片说明

Also - how do I not have the red border?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM