0

Initially I wanted to do it with ItemsControl but I couldn't think of anything other than using one ItemsControl for each group (Non Current Assets, Current Assets, etc.). To reduce the complexity I've used TreeView instead to present the information and with that here's how it looks:

enter image description here

Not bad! What I want now is to add sub group total for each Bold head and two group total: one for Non Current Assets and Current Assets and another for Non Current Liabilities, Current Liabilities and Fund. Here's the xaml for the TreeView:

<TreeView ItemsSource="{Binding BalanceSheet}"
        HorizontalContentAlignment="Stretch"
        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
        BorderThickness="0">
    <TreeView.ItemContainerStyle>
        <Style TargetType="TreeViewItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TreeViewItem">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="40"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <ContentPresenter ContentSource="Header" 
                                            Grid.ColumnSpan="2"/>
                            <ItemsPresenter Grid.Row="1" Grid.Column="1" 
                                        Name="ItemsHost"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </TreeView.ItemContainerStyle>
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding Ledgers}">
            <TextBlock Text="{Binding Book}" FontWeight="Bold" FontSize="14"/>
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <DockPanel>
                        <TextBlock Text="{Binding Ledger}"/>
                        <TextBlock HorizontalAlignment="Right" 
                                Text="{Binding Amount, StringFormat='N0'}"/>
                    </DockPanel>
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

and the Data Structures:

List<Balances> balanceSheet;
public List<Balances> BalanceSheet { get => balanceSheet; set { balanceSheet = value; OnPropertyChanged(); } }

public class Balances
{
    public string Book { get; set; }
    public List<Balance> Ledgers { get; set; }
    public Balances()
    {
        Ledgers = new List<Balance>();
    }
}

public class Balance
{
    public string Book { get; set; }
    public string Ledger { get; set; }
    public int Amount { get; set; }
}

Is it possible to use HeaderedItemsControl instead of Treeview? I haven't seen any good example of HeaderedItemsControl to work with.

  • 1
    https://stackoverflow.com/questions/3883955/wpf-itemscontrol-itemtemplate-border-with-groupstyle – ASh Jun 15 '20 at 21:51
  • @ASh, sub grouping done. After looking at a few examples I've used an IvalueConverter to compute the subgroup sum from `CollectionViewSource`. Now stuck at the grouping of subgroups eg. Total of Assets. –  Jun 15 '20 at 23:28
  • It was as simple as just adding one more property as group descriptor to get grouping of subgroups, great! –  Jun 15 '20 at 23:43

0 Answers0