Reputation: 89
I'm using MahApps library in my app, the default style of datagrid cell doesn't have any borders:
but I want the DataGrid to look like this:
So I've started with:
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Height"
Value="33" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Padding"
Value="5,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border x:Name="border"
Background="Transparent"
BorderBrush="Black"
BorderThickness="1"
Padding="0,10,0,10"
SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
but nothing changes, so I assume that I'm missing Based On={} attribute but I have no clue, I've asked for help MathApps team but no help...
Upvotes: 3
Views: 1581
Reputation: 108
Setting GridLinesVisibility="All"
on the DataGrid
control itself will give you the inner borders.
Note it doesn't give you the outside borders still, but it's a lot easier than editing the default template.
If you really want to get the outside borders, then you'll need to override the default template.
The MahApps default DataGridCell template key is MetroDataGridCell
, so you will need to use <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">
Upvotes: 5