I am trying to apply some styles to a Datagrid, but I am getting an error.
I am trying to apply rounded corners to a DataGrid
.
This is the error I am getting on , <Setter.Value>
The attachable property 'Value' was not found in type 'Setter'
<Style TargetType="{x:Type DataGrid}">
<Setter Property="RowHeaderWidth" Value="0" />
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid}">
<Grid>
<Border CornerRadius="5"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Style>
I found this question Datagrid template with rounded corners, but it does help with my question.
How do I get this to work?
Try this, you'll be Ok.
<Style TargetType="{x:Type DataGrid}">
<Setter Property="RowHeaderWidth" Value="0" />
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid}">
<Border Background="Red" CornerRadius="5">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You actually didn't specify the name of the property for the Setter.Value
. The
<Setter.Value></Setter.Value>
must be enclosed inside a
<Setter Property="NameOfthePropertyToSetTheValueFor"></Setter>
For the case of CornerRadius
the property must be Template
.