gpt4 book ai didi

c# - 删除 wpf datagrid 上的所有边框

转载 作者:太空宇宙 更新时间:2023-11-03 22:56:49 24 4
gpt4 key购买 nike

我对 WPF 有点陌生,我找不到完全消除单元格中所有边框、填充和边距的方法。我想要的是 table 上根本没有白色,鱼卵之间只有一条简单的水平线。

这是我得到的截图:

enter image description here

这是我想要得到的截图:

enter image description here

到目前为止,我有这个简化的代码:

<DataGrid IsReadOnly="True" AllowDrop="True" ItemsSource="{Binding Mode=OneWay, Source={StaticResource imageInfoListView}}" 
AutoGenerateColumns="False" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ColumnWidth="*"
FontSize="10" GridLinesVisibility="Horizontal" CanUserResizeColumns="False"
CanUserResizeRows="False" BorderThickness="0">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock TextWrapping="WrapWithOverflow" Text="{Binding}" TextAlignment="Center" FontSize="9"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGridCheckBoxColumn Header="Guides" Binding="{Binding Guides}">
<DataGridCheckBoxColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{Binding GuidesBrush}"/>
</Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
<DataGridTextColumn Header="Width" Binding="{Binding Width}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding WidthBrush}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Height" Binding="{Binding Height}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding HeightBrush}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Resolution" Binding="{Binding Resolution}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding ResolutionBrush}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Icc Model" Binding="{Binding IccModel}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding IccModelBrush}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Compression" Binding="{Binding Compression}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding CompressionBrush}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Errors" Binding="{Binding Errors}" Visibility="Hidden" />
</DataGrid>

但我找不到完全删除我不想要的所有内容的方法。有什么线索吗?

最佳答案

你已经有了 GridLinesVisibility="Horizo​​ntal"

您还需要的属性是 BorderThickness

但另一个问题是您定义了 DataGrid.CellStyle,然后定义了不相关的 DataGridTextColumn.CellStyle

创建默认的 DataGridCell 样式并在 CellStyles 列中使用 BasedOn 属性:

<DataGrid.Resources>
<Style TargetType="DataGridCell">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</DataGrid.Resources>
<!--...-->
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="Background" Value="{Binding WidthBrush}"/>
</Style>
</DataGridTextColumn.CellStyle>

关于c# - 删除 wpf datagrid 上的所有边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45018037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com