【发布时间】:2019-04-18 07:42:10
【问题描述】:
我的 WPF 项目中的 ListView / GridView 组合的布局有问题。列标题只是没有跨越父 ListView 的整个宽度。我试图到处查找文档,但没有找到有关底层容器/控件模板的任何线索。
我猜标题的标准控件模板包含一些我不关心的东西,我就是无法理解它。
(简化的)ListView 在包含标题的行的左侧和右侧有几个像素空间,其中父 ListView 的背景是可见的:
https://i.imgur.com/XijV88a.jpg
问题:如何使列标题跨越 ListView 的整个宽度并使少数像素空间消失?
我的 XAML:
<ListView Padding="0"
BorderThickness="0"
Background="Red">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="LightGray" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="Black" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Header="1" Width="40"/>
<GridViewColumn Header="2" Width="40"/>
<GridViewColumn Header="3" Width="40"/>
</GridView>
</ListView.View>
<ListViewItem> 1 </ListViewItem>
<ListViewItem> 2 </ListViewItem>
</ListView>
到目前为止,实现我想要的外观的唯一方法是将列表视图的背景更改为与标题相同的颜色 - 不过,必须有更好的方法。任何帮助表示赞赏!
【问题讨论】:
标签: wpf xaml listview gridview columnheader