代码之家  ›  专栏  ›  技术社区  ›  Archie

更改datagrid wpf中每个组的头

  •  0
  • Archie  · 技术社区  · 15 年前

    我有一个datagrid,其中我根据作者对行进行了分组。

    我用Author类对象的集合绑定了datagrid, 其中Author类有三个属性,分别是Book、Publication和Number of copies,它们对应于datagrid中组中的列。

    我的问题是我想显示每个作者组的“份数”的总和。我没有得到的是如何计算总和,因为它是针对一个组,而不是针对每个对象或total datagrid。

    能做到吗?

    1 回复  |  直到 5 年前
        1
  •  0
  •   GilShalit    13 年前

    奇怪的是,没有人回答这个问题,对@Archie来说可能已经太晚了,或者更可能他早就找到了答案。但不管怎样,还是这样:

    <GroupStyle.ContainerStyle>
        <Style TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander Loaded="GroupHeaderExpander_Loaded">
                            <Expander.Header>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Author: "/>
                                    <TextBlock Text="{Binding Path=Name}"/>
                                    <TextBlock Text=" "/>
                                    <TextBlock Text="{Binding Path=ItemCount}"
                                               FontStyle="Italic"/>
                                    <TextBlock Text=" Books" FontStyle="Italic"/>
                                </StackPanel>
                            </Expander.Header>
                            <ItemsPresenter>
    
                            </ItemsPresenter>
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </GroupStyle.ContainerStyle>
    

    高温