WPF的ListView组重复列标题 [英] WPF ListView groups repeat column headers
问题描述
有没有办法使用分组CollectionViewSource的ListView控件的来源,当重复每组ListView.GridView内的列标题?
Is there a way to repeat the column headers inside each group of a ListView.GridView when using a grouped CollectionViewSource as the source of the ListView?
我使用的是 http://msdn.microsoft.com/的例子EN-US /库/ ms754027.aspx 它使用一个扩展控件来显示每个组。
I am using the example at http://msdn.microsoft.com/en-us/library/ms754027.aspx which uses an Expander control to display each group.
我想列标题出现在扩展的每个组内,而不是在ListView控件的顶部。
I would like the column headers to appear inside the expander for each group instead of at the top of the ListView.
推荐答案
我没有尝试过这一点,但你可以包括你的组头里面GridViewHeaderRow presenters:
I haven't tried this, but you may be able to include GridViewHeaderRowPresenters inside your group headers:
<GridViewHeaderRowPresenter
DataContext="{Binding View, RelativeSource={RelativeSource FindAncestor,ListView,1}}"
Columns="{Binding Columns}"
ColumnHeaderContainerStyle="{Binding ColumnHeaderContainerStyle}"
ColumnHeaderTemplate="{Binding ColumnHeaderTemplate}"
ColumnHeaderTemplateSelector="{Binding ColumnHeaderTemplateSelector}"
AllowsColumnReorder="{Binding AllowsColumnReorder}"
ColumnHeaderContextMenu="{Binding ColumnHeaderContextMenu}"
ColumnHeaderToolTip="{Binding ColumnHeaderToolTip}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
如果不工作,一是安全可靠的方式来做到这一点是添加一个画着,在GridView的顶部引用一个且只有GridViewHeaderRow presenter一个的VisualBrush一个矩形。
If that doesn't work, one sure-fire way to do it is to add a Rectangle that is painted with a VisualBrush that references the one-and-only GridViewHeaderRowPresenter at the top of the GridView.
这可以用一个附加的属性来完成要在矩形使用。当连接的属性设置,它会注册一个低优先级调度回调:
This can be done with an attached property to be used on the Rectangle. When the attached property is set, it registers a low priority Dispatcher callback that:
- 扫描了可视化树到ListView
- 搜索,直到它找到GridViewHeaderRow presenter
- 构建的VisualBrush,并将其设置为填充的矩形,和
该矩形本身将是这样的:
The Rectangle itself would be something like this:
<Rectangle HorizontalAlignment="Stretch"
Height="{Binding Fill.Visual.RenderHeight}"
my:GridViewHeaderHelper.SearchForHeaderRowPresenterAndSetFill="True" />
这篇关于WPF的ListView组重复列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!