c# - 数据网格 : Have a stable/fixed row for a "group" of items

标签 c# wpf wpfdatagrid

我需要创建一个显示客户列表(包括他们的收入)的 DataGrid。我有两个数据表(客户/收入),我将它们合并到一个查询中,结果是客户/收入项目的列表。

我现在想在一张表中显示所有客户,包括他们的收入,但不为每个收入行复制/显示每个客户。所以我想在绘制一次后隐藏客户的所有其他绘图。

客户行应始终位于顶部。排序应该是可能的。换句话说,我正在寻找没有组的分组功能。

Regular display when opening for the first time

客户的列应该不会出现这样的情况:

enter image description here

另一个选项可能是分组,但我希望在分组元素中也有相同的“列”,如显示和调整大小行为。

非常欢迎任何想法。

最佳答案

您可以将收入列的 CellTemplate 替换为自己包含 DataGrid 的模板。

pic unsorted

pic sorted

XAML

<DataGrid.Columns>
    <DataGridTextColumn Header="Customer" Binding="{Binding Customer}" >
    </DataGridTextColumn>
    <DataGridTextColumn Header="Birth Date" Binding="{Binding Date}" >
    </DataGridTextColumn>
    <DataGridTemplateColumn Header="Income" >
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <DataGrid ItemsSource="{Binding IncomeList}" 
                                  AutoGenerateColumns="False"
                                  HeadersVisibility="None"
                                  CanUserAddRows="False" 
                                  CanUserDeleteRows="False">
                    <DataGrid.Columns>
                        <DataGridTextColumn
                                      Width="*"
                                      IsReadOnly="True" 
                                      Binding="{Binding Path=.}">
                        </DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
</DataGrid.Columns>

关于c# - 数据网格 : Have a stable/fixed row for a "group" of items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164027/

相关文章:

C# Comport - 可能丢失数据

wpf - Datagrid 行的静态数据是否可以纯粹在 XAML 中定义,即没有代码背后?

c# - 同步到异步的异步工作有奇怪的行为

c# - 如何从派生类中获取基类实例

c# - "Realistic"乒乓球碰撞

c# - 捕获所有错误,而不仅仅是单个按钮

c# - DispatcherTimer 在更新 UI 时每分钟变慢

c# - 可以通过在WPF中平滑地改变字体粗细来脉冲文本吗?

wpf - 初始数据网格排序

wpf - DataGrid.RowStyle 仅适用于初始绑定(bind)