Reputation:
I want to remove a top border from cells containing empty strings. I tried to use a solution similar to this: https://social.msdn.microsoft.com/Forums/vstudio/en-US/dac1e5c6-d3b0-4b71-84e7-f484d6165039/datagrid-and-cell-borders?forum=wpf
Relevant part of my XAML:
<DataGridTextColumn Header="Header" Binding="{Binding [0]}">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding [0]}" Value="">
<Setter Property="BorderBrush" Value="Blue" />
<Setter Property="BorderThickness" Value="1,0,1,1" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
(I use blue color just to make it clear what happens). It correctly detects cells with empty strings, but it doesn't remove top border, as I expect. Instead, it adds another layer of blue borders:
How can I remove top border from cells with empty string?
Upvotes: 0
Views: 279
Reputation: 48179
As noted in the comments, what you are probably encountering is the default "GRIDLINES" for the data grid. By default they are on for all (both horizontal and vertical). So, even if you are setting each data grid CELL for a given top border as 0 or 1 for left,top,right,bottom, this does not supersede the main grid.
You can turn that off by setting the gridlines=none. But now, you have the issue of trying to force each CELL specific borders.
If the first row cell has data and you DO have the borders on each side, it does not know what is coming next to turn it's bottom OFF. The only way I could possibly think of resolving this is to have a custom column in the data source to identify border settings and pre-scan for current/next to determine if it should be on or off. But that would be a problem by allowing the datagrid to be sorted by user clicking on a grid column header and that work goes right out the window...
What is the need to explicitly turn off the top border between rows. Is it really necessary? To get rid of too many lines, I might just try by setting the grid lines to Horizontal only.
Upvotes: 1