页面显示不同的订单号,每个订单号包含多个订单项,需要总计金额并在组头中显示。请帮助显示每个订单号的总金额。
TotalAmount字段不会与Group标题名称(订单号)一起显示。
<abcd:DetailsListView x:Name="EncumbranceEntriesList" Grid.Row="1"
ItemsSource="{Binding CurrentEncumbranceJournalEntries}"
SelectionMode="Extended" ShowGroupItemCount="True"
IsSortingEnabled="False"
ahtd:ListBoxExtensions.HasBindableSelectedItems="True">
<i:Interaction.Behaviors>
<b:DetailsListViewStatePersistenceBehavior
ListViewState="{e:UISettingBinding EncumbranceJournalTabListViewState}"/>
</i:Interaction.Behaviors>
<ListView.ContextMenu>
<ContextMenu>
<ContextMenu.Resources>
<Style TargetType="{x:Type Image}" BasedOn="{StaticResource CommandIconStyle}"/>
</ContextMenu.Resources>
<MenuItem Header="_Refresh" InputGestureText="F5"
Command="{StaticResource RefreshCommand}">
<MenuItem.Icon>
<Image Source="{DynamicResource {local:ThemeResourceKey IconRefresh}}"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ListView.ContextMenu>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick"/>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<ContextMenu.Resources>
<Style TargetType="{x:Type Image}" BasedOn="{StaticResource CommandIconStyle}"/>
</ContextMenu.Resources>
<MenuItem Header="_Open Purchase Order" Command="{StaticResource OpenPOCommand}" CommandParameter="{Binding PurchaseOrderDetail.PurchaseOrder}">
<MenuItem.Icon>
<Image Source="{DynamicResource {local:ThemeResourceKey IconOpen}}"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<abcd:DetailsView>
<abcd:DetailsViewColumn Header="PO #" Width="140"
IsInitiallyVisible="False" IsUserHidable="False"
DisplayMemberBinding="{Binding PurchaseOrderDetail.PurchaseOrder.DisplayNumber}"
SortPropertyName="PurchaseOrderDetail.PurchaseOrder.DisplayNumber"
GroupPropertyName="PurchaseOrderDetail.PurchaseOrder.DisplayNumber"/>
<abcd:DetailsViewColumn Header="Line Item" Width="200"
DisplayMemberBinding="{Binding PurchaseOrderDetail.ShortItemDescription}"/>
<abcd:DetailsViewColumn Header="Date" Width="80"
DisplayMemberBinding="{Binding EntryDate, StringFormat=\{0:d\}}"
SortPropertyName="EntryDate" DefaultSortDirection="Descending"/>
<abcd:DetailsViewColumn Header="Encumbrance" Width="100"
SortPropertyName="Amount">
<abcd:DetailsViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding EncumbranceAmount, StringFormat={}{0:C}}"
TextAlignment="Right"/>
</DataTemplate>
</abcd:DetailsViewColumn.CellTemplate>
</abcd:DetailsViewColumn>
<abcd:DetailsViewColumn Header="Liquidation" Width="100"
SortPropertyName="Amount">
<abcd:DetailsViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding LiquidationAmount, StringFormat={}{0:C}}"
TextAlignment="Right"/>
</DataTemplate>
</abcd:DetailsViewColumn.CellTemplate>
</abcd:DetailsViewColumn>
</abcd:DetailsView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text=" {Binding TotalAmount, StringFormat={}{0:C}}" FontSize="22" Foreground="Black" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</abcd:DetailsListView>
</Grid>
</etk:BusyIndicator>
背后的代码是
private void AutoSortList()
{
ICollectionView dataView = CollectionViewSource.GetDefaultView(EncumbranceEntriesList.ItemsSource);
if (dataView != null && dataView.SortDescriptions.Count == 0)
{
dataView.SortDescriptions.Add(new SortDescription("PurchaseOrderDetail.PurchaseOrder.DisplayNumber", ListSortDirection.Ascending));
dataView.SortDescriptions.Add(new SortDescription("PurchaseOrderDetail.TransactionDate", ListSortDirection.Ascending));
dataView.SortDescriptions.Add(new SortDescription("EntryDate", ListSortDirection.Ascending));
EncumbranceEntriesList.Group("PurchaseOrderDetail.PurchaseOrder.DisplayNumber");
}
}
答案 0 :(得分:0)
在GroupStyle中,你还有HeaderTemplate,它为你提供了“名字”和“ItemCount中”。它们分别对应于组的名称和其中包含的项目数。
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} ({1})">
<Binding Path="Name" />
<Binding Path="ItemCount" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>