wpfdatagridviewcellstyle

A style for a datagridviewcell is applied but not visible


I made a template for a cell in a column of a wpf datagrid.

<DataGridTemplateColumn Header="R" >
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Border Width="10" Height="10" BorderThickness="3">
                <Border.Style>
                    <Style TargetType="Border">
                        <Setter Property="Background" Value="Green"/>
                        <Setter Property="BorderThickness" Value="3"/>
                    </Style>
                </Border.Style>
                <Rectangle Width="7" Height="7" Fill="Red"/>
            </Border>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Wpf inspector shows that the style is applied, but it is not visible. Why not?


Solution

  • If by it is not visible you mean that you don't see the border around your Rectangle then it's because you didn't set Border.BorderBrush property.

    If changed like this, you'll see black border around your red Rectangle:

    <Border Width="10" Height="10" BorderThickness="3" BorderBrush="Black">
    

    Green background you won't see because it is under Rectangle.