I have a DataGrid that is showing one fixed horizontal line (gridline?) after 9th record down the list. When scrolling through the list, the line stays fixed and it does not scroll with the list.
Even when I set GridLinesVisibility="None"
I can still see the line sitting there.
If I add a border to the DataGridRow
, the respective line seems to stay midway between the rows as if it was a gridline or some sort of separator line.
Is this some sort of known artefact or am I going nuts?
This is my DataGrid:
<DataGrid Grid.Row="1"
GridLinesVisibility="None"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
IsReadOnly="True"
ItemsSource="{ Binding Path=Users }"
SelectedItem="{ Binding SelectedUser, Mode=TwoWay }" > <!-- SelectedIndex="{ Binding SelectedRowIndex }" -->
<DataGrid.Columns>
<DataGridTextColumn Header="User ID" Binding="{Binding UserID}" Width="Auto"/>
<DataGridTextColumn Header="Initials" Binding="{Binding Initials}" Width="Auto"/>
<DataGridTextColumn Header="Surname" Binding="{Binding Surname}" Width="Auto"/>
<DataGridTextColumn Header="Given Names" Binding="{Binding GivenNames}" Width="Auto"/>
<DataGridTextColumn Header="Active" Binding="{Binding Active, Converter={ StaticResource booleanToYesNoConverter} }" Width="Auto">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{ Binding Active, Converter={ StaticResource activeInactiveBackgroundColorConverter }}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Many thanks for help.
Edited: After fiddling with this issue a bit more, I found that if I start with an empty datagrid and then add one record at a time, it seems that the misterious line is just the background colour of the datagrid showing in between the records at the 9th and 10th position down the visible part of the list (what's in the view port). Then, if I set the background color of the datagrid to transparent, the line is no longer showing:
<Style TargetType="DataGrid">
<Setter Property="Background" Value="Transparent"/>
</Style>
This is really weird. Anyone has any explanation for this?
This might be due to layout math creating a small gap. Try setting UseLayoutRounding="True"
and/or SnapsToDevicePixels="True"
on your DataGrid to see if it makes the issue go away.
In my shared styles, I set UseLayoutRounding="True"
on my Window
s to eliminate blurry lines and other layout issues.