I am currently working on a Listview grouping based on billing_id in my case. I can get a group by elements using GroupBy from LINQ, but before displaying I run into problems. It is displayed as a whole page, and not as a child of a PivotItem. My code is as follows.
First I created a CollectionViewSource in the page resources as follows
<Page.Resources>
<CollectionViewSource x:Key="cvs" x:Name="cvs" IsSourceGrouped="True" />
</Page.Resources>
Then I got the whole list using GroupBy and assigned it to this CollectionViewSource as follows
var billingGroupByList = taskBillingList.GroupBy(b => b.billing_type_id).Select(grp => grp.ToList()).ToList();
this.cvs.Source = billingGroupByList;
After that, I created an interface, including the Grouping style and ItemTemplate, as shown below.
<Pivot>
<Pivot.Items>
<PivotItem x:Name="ChargesPivot"
Header="Charges"
Background="White"
Margin="0,-35,0,0">
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel>
<Grid Background="#F8F8FB" BorderBrush="#D6D6D6" BorderThickness="5,0,0,0">
<TextBlock x:Name="charges"
Text="Charges"
FontSize="18"
Margin="10"
Foreground="Gray"/>
</Grid>
<ListView x:Name="chargesView"
ItemContainerStyle="{StaticResource GenericListViewContainerStyle}"
ItemsSource="{Binding Source={StaticResource cvs}}" SelectionChanged="chargesView_SelectionChanged"
Margin="5">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding billing_type}"
FontSize="16"
FontWeight="SemiBold"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".25*"/>
<ColumnDefinition Width=".25*"/>
<ColumnDefinition Width=".25*"/>
<ColumnDefinition Width=".25*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="billing_date"
FontSize="16"
Margin="4,1,4,4"
Grid.Column="0"
FontWeight="SemiBold"
Text="{Binding Path = quantity}"/>
<TextBlock x:Name="charge"
FontSize="16"
Margin="4,1,4,4"
Grid.Column="1">
<Run Text="{Binding Path = charge}"/>
<Run Text=" "/>
<Run Text="{Binding Path = charge_uom}"/>
</TextBlock>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Grid>
</ScrollViewer>
</PivotItem>
- , ? Charge , . .
