WPF无法移除DataGrid单元格的右边框。

huangapple go评论86阅读模式
英文:

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.

WPF无法移除DataGrid单元格的右边框。

I've tried to set the cell BorderThickness to 0, but the right border line still exists.
The style xaml code is as below.

&lt;!-- DataGrid Cell --&gt;
&lt;Style TargetType=&quot;{x:Type DataGridCell}&quot; x:Key=&quot;RightCell&quot;&gt;
&lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;0 0 0 0&quot;/&gt;
&lt;/Style&gt;
&lt;!--Text Block--&gt;
&lt;Style TargetType=&quot;{x:Type TextBlock}&quot; x:Key=&quot;RegularTextBlock&quot;&gt;
    &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Center&quot;/&gt;
    &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Center&quot;/&gt;
    &lt;Setter Property=&quot;Background&quot; Value=&quot;Transparent&quot;/&gt;
    &lt;Setter Property=&quot;FontSize&quot; Value=&quot;{StaticResource FontSizeSuperSmall}&quot; /&gt;
&lt;/Style&gt;

The UI xaml code is as below.

&lt;!-- DataGrid --&gt;
&lt;DataGrid Grid.Column=&quot;0&quot; 
Margin=&quot;0,0,10,0&quot; 
x:Name=&quot;ResultDataGrid&quot;
ItemsSource=&quot;{Binding ResultList, UpdateSourceTrigger=PropertyChanged}&quot;
AutoGenerateColumns=&quot;False&quot;
CanUserAddRows=&quot;False&quot;
CanUserSortColumns=&quot;False&quot;
CanUserDeleteRows=&quot;False&quot;
CanUserReorderColumns=&quot;False&quot;
GridLinesVisibility=&quot;All&quot;
HorizontalScrollBarVisibility=&quot;Auto&quot;
VerticalScrollBarVisibility=&quot;Auto&quot;
HorizontalAlignment=&quot;Center&quot;
RowHeaderWidth=&quot;0&quot;
BorderBrush=&quot;{StaticResource CustomPureBlackBrush}&quot;
BorderThickness=&quot;1&quot;
Background=&quot;{StaticResource CustomPureWhiteBrush}&quot;&gt;
&lt;!-- Set Columns --&gt;
&lt;DataGrid.Columns&gt;
&lt;!-- First two columns have been deleted for simplicity.--&gt;
&lt;!-- Type Column--&gt;
&lt;DataGridTemplateColumn Header=&quot;Type&quot; Width=&quot;*&quot; IsReadOnly=&quot;True&quot; HeaderStyle=&quot; 
   {StaticResource FlattenRightHeader}&quot; CellStyle=&quot;{StaticResource RightCell}&quot; &gt;
  &lt;DataGridTemplateColumn.CellTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;Grid&gt;
              &lt;TextBlock Name=&quot;BuyTYpe&quot; Text=&quot;test&quot; Style=&quot;{StaticResource RegularTextBlock}&quot; /&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  &lt;/DataGridTemplateColumn.CellTemplate&gt;
&lt;/DataGridTemplateColumn&gt;
&lt;/DataGrid.Columns&gt;
&lt;/DataGrid&gt;

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=&quot;None&quot;

If you need those lines, you can use styles instead.

huangapple
  • 本文由 发表于 2023年8月9日 09:12:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76863978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定