无法获取要显示的列表视图组扩展器标头

时间:2014-08-07 09:01:41

标签: c# wpf

我正在尝试将一个项目列表分组到WPF列表视图中 - 它工作正常,但我无法显示扩展程序标题。

我按如下方式设置组样式:

<!--  Styles the groups  -->
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Expander BorderBrush="LightBlue"
                                            BorderThickness="1"
                                            IsExpanded="True"
                                                  Name="groupExpander"
                                            Header="{Binding Family}">

                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>

并且列表视图项源绑定在后面的代码中:

//group by shape family
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(GetShapes());
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Family");
view.GroupDescriptions.Add(groupDescription);
ImagesListView.ItemsSource = view;

最后我绑定到了这个对象的List(我想在族字段中对该字符串进行分组,该字符串出现在组头中:

public class Shape
{
        public int ID { get; private set; }
        public byte[] Image { get; private set; }
        public string Description { get; private set; }
        public string Family { get; private set; }

}

我没做什么或做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要更改

Header="{Binding Family}"

Header="{Binding Name}"

每个组都是CollectionViewGroup,其中Name是您按

分组的值
相关问题