如何删除DataGrid最后一行的底部边框
How to remove bottom border of the last row of DataGrid
如您所见,数据网格中最后一行的底部边框靠近数据网格的边框,使其看起来很难看。我该如何解决这个问题?
<DataGrid HeadersVisibility="Column"
ItemsSource="{Binding Path=DevLengths}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeRows="False"
CanUserResizeColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Size" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Length of Splice" Binding="{Binding LengthOfSplice}"/>
<DataGridTextColumn Header="Length of Development" Binding="{Binding LengthOfDevelopment}"/>
<DataGridTextColumn Header="Ldh" Binding="{Binding Ldh}"/>
<DataGridTextColumn Header="Length of Hook" Binding="{Binding LengthOfHook}" Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Margin" Value="0,0,-1,0"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
您可以为您的 DataGrid
设置 BorderThickness="1,1,1,0"
。这将删除底部边框并将顶部、左侧、右侧设置为默认值 1。
因此您的新代码将是:
<DataGrid HeadersVisibility="Column"
ItemsSource="{Binding Path=DevLengths}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeRows="False"
CanUserResizeColumns="False"
BorderThickness="1,1,1,0">
<DataGrid.Columns>
<DataGridTextColumn Header="Size" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Length of Splice" Binding="{Binding LengthOfSplice}"/>
<DataGridTextColumn Header="Length of Development" Binding="{Binding LengthOfDevelopment}"/>
<DataGridTextColumn Header="Ldh" Binding="{Binding Ldh}"/>
<DataGridTextColumn Header="Length of Hook" Binding="{Binding LengthOfHook}" Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Margin" Value="0,0,-1,0"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
如您所见,数据网格中最后一行的底部边框靠近数据网格的边框,使其看起来很难看。我该如何解决这个问题?
<DataGrid HeadersVisibility="Column"
ItemsSource="{Binding Path=DevLengths}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeRows="False"
CanUserResizeColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Size" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Length of Splice" Binding="{Binding LengthOfSplice}"/>
<DataGridTextColumn Header="Length of Development" Binding="{Binding LengthOfDevelopment}"/>
<DataGridTextColumn Header="Ldh" Binding="{Binding Ldh}"/>
<DataGridTextColumn Header="Length of Hook" Binding="{Binding LengthOfHook}" Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Margin" Value="0,0,-1,0"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
您可以为您的 DataGrid
设置 BorderThickness="1,1,1,0"
。这将删除底部边框并将顶部、左侧、右侧设置为默认值 1。
因此您的新代码将是:
<DataGrid HeadersVisibility="Column"
ItemsSource="{Binding Path=DevLengths}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeRows="False"
CanUserResizeColumns="False"
BorderThickness="1,1,1,0">
<DataGrid.Columns>
<DataGridTextColumn Header="Size" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Length of Splice" Binding="{Binding LengthOfSplice}"/>
<DataGridTextColumn Header="Length of Development" Binding="{Binding LengthOfDevelopment}"/>
<DataGridTextColumn Header="Ldh" Binding="{Binding Ldh}"/>
<DataGridTextColumn Header="Length of Hook" Binding="{Binding LengthOfHook}" Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Margin" Value="0,0,-1,0"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>