英文:
WPF cannot remove right border for DataGrid cell
问题
我正在使用DataGrid来显示一些信息。然而,每一行的右侧列显示了一个额外的边框线,与DataGrid的边框不对齐。
我尝试将单元格的BorderThickness设置为0,但右侧边框线仍然存在。
以下是样式的XAML代码。
以下是UI的XAML代码。
<DataGrid.Columns>
<DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGrid.Columns>
有人能给我一些建议吗?谢谢。
英文:
I'm using DataGrid to show some information. However every row's right column displays an extra border line which does not align with the DataGrid border.
I've tried to set the cell BorderThickness to 0, but the right border line still exists.
The style xaml code is as below.
<!-- DataGrid Cell -->
<Style TargetType="{x:Type DataGridCell}" x:Key="RightCell">
<Setter Property="BorderThickness" Value="0 0 0 0"/>
</Style>
<!--Text Block-->
<Style TargetType="{x:Type TextBlock}" x:Key="RegularTextBlock">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="FontSize" Value="{StaticResource FontSizeSuperSmall}" />
</Style>
The UI xaml code is as below.
<!-- DataGrid -->
<DataGrid Grid.Column="0"
Margin="0,0,10,0"
x:Name="ResultDataGrid"
ItemsSource="{Binding ResultList, UpdateSourceTrigger=PropertyChanged}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserSortColumns="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
GridLinesVisibility="All"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
HorizontalAlignment="Center"
RowHeaderWidth="0"
BorderBrush="{StaticResource CustomPureBlackBrush}"
BorderThickness="1"
Background="{StaticResource CustomPureWhiteBrush}">
<!-- Set Columns -->
<DataGrid.Columns>
<!-- First two columns have been deleted for simplicity.-->
<!-- Type Column-->
<DataGridTemplateColumn Header="Type" Width="*" IsReadOnly="True" HeaderStyle="
{StaticResource FlattenRightHeader}" CellStyle="{StaticResource RightCell}" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Name="BuyTYpe" Text="test" Style="{StaticResource RegularTextBlock}" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Could someone give me some suggestions? Thanks.
答案1
得分: 0
我相信这是由于网格线引起的。尝试将其关闭:
GridLinesVisibility="None"
如果你需要这些线条,可以使用样式来代替。
英文:
I believe it is caused by the grid lines. Try turning them off:
GridLinesVisibility="None"
If you need those lines, you can use styles instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论