Expander Header不显示组字段内容,仅显示ItemsCount

时间:2013-07-10 13:46:43

标签: wpf wpfdatagrid lucene.net

我有一个带有GroupStyle的WPF DataGrid

<DataGrid.GroupStyle>
                <GroupStyle>

                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True">
                                            <Expander.Header>
                                                <StackPanel>
                                                    <TextBlock Text="{Binding Path=citta}" Margin="5,0,0,0" Width="100" FontWeight="Bold"/>
                                                    <TextBlock Text="{Binding Path=ItemCount}" />
                                                </StackPanel>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </DataGrid.GroupStyle>
代码背后的代码:

var qq = (from a in q select new { formareg = a.Get("formareg"), citta = a.Get("citta"), conteggio = a.Get("conteggio"), parametro = a.Get("idcitta").ToString() + "|" + a.Get("formareg") }).OrderBy(x => x.citta).ToList();

                                ListCollectionView cv = new ListCollectionView(qq);
                                cv.GroupDescriptions.Add(new PropertyGroupDescription("citta"));
                                GrigliaDati.ItemsSource = cv;

一切正常但在每组的标题中我只看到ItemCount而不是Path = citta。

怎么了?

1 个答案:

答案 0 :(得分:3)

与我之前对this问题的回答相同,这是因为你绑定到了错误的字段。您需要绑定到组名,而不是绑定到您分组的字段。尝试这样的想法:

<TextBlock Text="{Binding Path=Name}">

每个组都是CollectionViewGroup,它有自己的属性,可以在指定组头时使用。