Reputation: 163
I have a DataGrid with 21 columns where the first column contains a date and the other twenty are monetary values, i.e. the number must be formatted right aligned with 2 decimal digits. Logically always three, three and one columns belong together so what I want to achieve is that grid lines are invisible but every third column should have a vertical border on the right side.
Any hint how to achieve that?
Upvotes: 3
Views: 6461
Reputation: 270
If you want to maintain the default style (In my case MaterialDesign Style) define a style:
<Style
x:Key="MyDataGridCell"
BasedOn="{StaticResource MaterialDesignDataGridCell}"
TargetType="DataGridCell">
<Setter Property="BorderBrush" Value="Silver" />
<Setter Property="BorderThickness" Value="1" />
</Style>
Then apply the style to the DataGrid:
<DataGrid CellStyle="{StaticResource MyDataGridCell}"
GridLinesVisibility="None" >
<DataGrid.Columns>
<DataGridTextColumn
x:Name="Column1"
MinWidth="120"
Binding="{Binding Status}"
CanUserResize="False" /></DataGrid>
Upvotes: 0
Reputation: 169390
Define all columns explicitly in your XAML markup and define a CellStyle for every third column that sets the BorderBrush and BorderThickness of the DataGridCell. Something like this:
<DataGrid GridLinesVisibility="None" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding First}" />
<DataGridTextColumn Binding="{Binding Second}" />
<DataGridTextColumn Binding="{Binding Third}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="0 0 1 0" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Upvotes: 5