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

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

概述我有一个列表视图控件与分组和排序. 组标题是按降序排列的日期. 我试图找出如何按升序排序每个组头下的分组项目,但无法弄清楚如何完成它或者甚至可以使用ListView. 这是我到目前为止的XAML. 注意:ScheduledItemSearchResults是一个可观察的ScheduleItem集合,每个项目都有Title和ScheduleDate属性. <Grid x:Name="TxSchedu 我有一个列表视图控件与分组和排序.

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

我试图找出如何按升序排序每个组头下的分组项目,但无法弄清楚如何完成它或者甚至可以使用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>

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

总结

以上是内存溢出为你收集整理的c# – Wpf ListView是否可以以不同于组头的方式订购组项?全部内容,希望文章能够帮你解决c# – Wpf ListView是否可以以不同于组头的方式订购组项?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1236912.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存