【问题标题】:Cant get list view group expander header to display无法显示列表视图组扩展器标题
【发布时间】:2014-08-07 09:01:41
【问题描述】:

我正在尝试在 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;

最后我绑定到这个对象的列表(我想在家庭字段上分组,这个字符串出现在组标题中:

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; }

}

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

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    你需要改变

    Header="{Binding Family}"
    

    Header="{Binding Name}"
    

    每个组都是一个CollectionViewGroup,其中Name 是您分组依据的值

    【讨论】:

    • 我的天啊,非常感谢 - 用我的头撞上一杯冷咖啡 2 小时,就这么简单!
    猜你喜欢
    • 2013-04-17
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多