在WPF Toolkit的DataGrid中跨多行展开记录

5
有没有可能对WPF Toolkit的DataGrid进行样式设计,以使数据记录跨越多行?商业控件的屏幕截图示例

谢谢,
Ben

2个回答

4

从截图来看,该控件通过将图片右侧每列的单元格分成多行,营造了跨行的假象。也许您可以用同样的方法实现您想要的跨行效果。

<tk:DataGrid AutoGenerateColumns="False">
    <tk:DataGrid.Columns>
        <tk:DataGridTextColumn Header="ID" Binding="{Binding ID}" />
        <tk:DataGridTemplateColumn Header="Photo">
            <tk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Source="{Binding Photo}" />
                </DataTemplate>
            </tk:DataGridTemplateColumn.CellTemplate>
        </tk:DataGridTemplateColumn>
        <tk:DataGridTemplateColumn>
            <tk:DataGridTemplateColumn.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0">FirstName</TextBlock>
                    <TextBlock Grid.Row="1">LastName</TextBlock>
                </Grid>
            </tk:DataGridTemplateColumn.Header>
            <tk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="{Binding FirstName}" />
                        <TextBlock Grid.Row="1" Text="{Binding LastName}" />
                    </Grid>
                </DataTemplate>
            </tk:DataGridTemplateColumn.CellTemplate>
        </tk:DataGridTemplateColumn>
    </tk:DataGrid.Columns>
</tk:DataGrid>

4
工具包DataGrid或GridView无法实现ListView中的此功能。
但是,您可以通过自己的实现来尝试,因为我最近发现您可以使用GridViewHeaderRowPresenter(MSDN reference),将Columns属性设置为您想要的列:这将为您提供标题行。
然后,您可以使用GridViewRowPresenter(MSDN reference),将其附加到相同的Columns集合,并且您的行和标题中的列将被链接(调整标题大小,列会更改)。
在此处查看一个很好的示例:

http://msdn.microsoft.com/en-us/library/ms752313.aspx

为了实现堆叠效果,您可以创建一个ListView或ListBox,在每个项目中输出一对垂直堆叠的GridViewRowPresenter控件,每个控件都绑定到单独的列集合。然后,在您自己的自定义标题(就在控件上方)中,您将使用一对GridViewHeaderRowPresenter控件执行相同的操作。
您还可以添加其他任何希望添加的部分,例如示例截图中具有的文本/标签。
没有理由这不能工作。这不是预先构建的解决方案,但是通过干净的编程是可能的,它不是一种黑客方法,并且您可以完全控制其外观和功能!添加排序等功能也很容易,MSDN也有一个示例。
希望这有所帮助 - 如果对此的详细信息有更多问题,请在此处添加评论!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接