c# – Wpf ListView是否可以以不同于组头的方式订购组项?

我有一个列表视图控件与分组和排序.

标题是按降序排列的日期.

我试图找出如何按升序排序每个组头下的分组项目,但无法弄清楚如何完成它或者甚至可以使用ListView.

这是我到目前为止的XAML.

注意:ScheduledItemSearchResults是一个可观察的ScheduleItem集合,每个项目都有Title和ScheduleDate属性.

<Grid x:Name="TxScheduleItemResults"
              Grid.Column="1">
            <Grid.Resources>
                <CollectionViewSource Source="{Binding ScheduledItemSearchResults}" x:Key="scheduledItems">
                    <CollectionViewSource.sortDescriptions>
                        <scm:SortDescription PropertyName="Value.ScheduleDateTime" Direction="Descending"/>
                    </CollectionViewSource.sortDescriptions>
                    <CollectionViewSource.GroupDescriptions>
                        <dat:PropertyGroupDescription PropertyName="Value.ScheduleDateTime.Date" />
                    </CollectionViewSource.GroupDescriptions>
                </CollectionViewSource>
            </Grid.Resources>

            <ListView x:Name="ScheduledItemResultsList"
                      Style="{StaticResource TransparentListViewStyle}"
                      ItemContainerStyle="{StaticResource alternatingListViewItemStyle}" 
                      AlternationCount="2"
                      ItemsSource="{Binding Source={StaticResource scheduledItems}}"
                      >

                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Scheduled Items"
                                        Width="{Binding ElementName=ScheduledItemResultsList,Path=ActualWidth}"
                                        >
                            <GridViewColumn.HeaderTemplate>
                                <DataTemplate>
                                    <TextBlock Style="{StaticResource ModuleGroupHeader}"
                                               Text="{Binding}"
                                               />
                                </DataTemplate>
                            </GridViewColumn.HeaderTemplate>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox Text="{Binding Value.Title}" Width="200"/>
                                        <TextBox Text="{Binding Value.ScheduleDateTime,StringFormat={}{0:HH:mm:ss}}" Width="120"/>
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style targettype="{x:Type GroupItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <Expander IsExpanded="True">
                                                <Expander.Header>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="{Binding  Path=Items[0].Value.ScheduleDateTime.Date,StringFormat={}{0:dd/MM/yyyy}}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
                                                        <TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0" VerticalAlignment="Bottom" />
                                                        <TextBlock Text=" item(s)" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
                                                    </StackPanel>
                                                </Expander.Header>
                                                <ItemsPresenter />
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                </ListView.GroupStyle>
            </ListView>
        </Grid>

解决方法

您可以在一个CollectionViewSource中包含多个SortDescriptions元素:
<CollectionViewSource Source="{Binding ScheduledItemSearchResults}" x:Key="scheduledItems">
                <CollectionViewSource.sortDescriptions>
                    <!--This will sort groups-->
                    <scm:SortDescription PropertyName="Value.ScheduleDateTime.Date" />
                    <!--This will items-->
                    <scm:SortDescription PropertyName="Value.ScheduleDateTime" Direction="Descending"/>
                </CollectionViewSource.sortDescriptions>
                <CollectionViewSource.GroupDescriptions>
                    <dat:PropertyGroupDescription PropertyName="Value.ScheduleDateTime.Date" />
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource>

附:我不知道你究竟想要对它进行排序,但是如果你对第一组进行排序,然后对项目进行排序则应该有效.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...