C# ListBox Groupstyle显示:如何设计组名?

C# ListBox Groupstyle显示:如何设计组名?,c#,.net,xaml,C#,.net,Xaml,我想在列表框中按创建日期对项目(图像)进行分组。那么我就用这个代码: <ListBox.GroupStyle> <GroupStyle /> </ListBox.GroupStyle> 注意:我使用DateTimeToDateConverter()转换器,它返回没有时间的日期。参考: 使用定义组时,将显示视图对象 (一个物体或从中衍生出来的物体) )将每个组包装在CollectionViewGroup对象中 基本上,当您添加Prope

我想在列表框中按创建日期对项目(图像)进行分组。那么我就用这个代码:

<ListBox.GroupStyle>
            <GroupStyle />
</ListBox.GroupStyle>
注意:我使用DateTimeToDateConverter()转换器,它返回没有时间的日期。

参考:

使用定义组时,将显示视图对象 (一个物体或从中衍生出来的物体) )将每个组包装在CollectionViewGroup对象中

基本上,当您添加
PropertyGroupDescription
WPF时,实际上会生成一个。您需要绑定到属性,而不是DateCreated属性(WPF引擎为您创建的新CollectionViewGroup上不存在该属性)


Wow..太好了。。我真的很想念那一个。。非常感谢。现在它正在展出。
<ListBox.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <Border BorderBrush="Gray" BorderThickness="1" CornerRadius="8">
                            <TextBlock Text="{Binding Path=DateCreated}" FontWeight="Bold" HorizontalAlignment="Center"/>
                        </Border>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ListBox.GroupStyle>
ICollectionView view = CollectionViewSource.GetDefaultView(CollectedFiles);
        view.GroupDescriptions.Add(new PropertyGroupDescription("DateCreated", new DateTimeToDateConverter()));
        view.SortDescriptions.Add(new SortDescription("FileFullName", ListSortDirection.Ascending));
<ListBox.GroupStyle>
    <GroupStyle>
        <GroupStyle.HeaderTemplate>
             <DataTemplate>
                  <Border BorderBrush="Gray" BorderThickness="1" CornerRadius="8">
                       <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" HorizontalAlignment="Center" />
                  </Border>
              </DataTemplate>
          </GroupStyle.HeaderTemplate>
     </GroupStyle>
</ListBox.GroupStyle>