'Rounded DataGrid Corners?
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?
Solution 1:[1]
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.
Solution 2:[2]
You forgot a
< Setter Property="Template">
2 lines above the ControlTemplate declaration
*remove space before 'Setter':)
Solution 3:[3]
The indents are sort of helping you in the issue.
<Style TargetType="{x:Type DataGrid}">
<Setter Property="RowHeaderWidth" Value="0" />
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ControlTemplate">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid}">
<Grid>
?? <Border CornerRadius="5"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | thatguy |
| Solution 2 | Oyiwai |
| Solution 3 | Emad |
