title: Footer on ListView WPF
body: <p>I would like to add a footer to the <code>ListView</code> with the sum of two columns in his respective columns, Licenses and Scans, I found something similar (<a href="https://stackoverflow.com/questions/1287979/c-wpf-idea-how-to-display-the-last-row-of-a-listview-separately">Here</a>) but the footer is not being shown, if I add a 4 column into the <code>GridView</code>then the footer row is shown but without any values.<br>The <code>GridViewColumnHeader</code>contains a style which I would like to apply to the Footer as well (I have not pasted it to provide a Minimal, functional example)</p>
  
  <p>This is the expected view:<br>
  <a href="https://i.stack.imgur.com/LvUnu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LvUnu.png" alt="enter image description here"></a></p>
  
  <p>xaml<br></p>
  
  <pre><code>&lt;Window x:Class="WpfApp2.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:WpfApp2"
          xmlns:system="clr-namespace:System;assembly=mscorlib"
          xmlns:utils="Helper"
          mc:Ignorable="d"
          Title="MainWindow"
          Height="450"
          Width="800"&gt;
      &lt;Window.DataContext&gt;
          &lt;local:ViewModel /&gt;
      &lt;/Window.DataContext&gt;
      &lt;Window.Resources&gt;
          &lt;CollectionViewSource x:Key="ViewSource"
                                Source="{Binding DataList}"&gt;
              &lt;CollectionViewSource.GroupDescriptions&gt;
                  &lt;PropertyGroupDescription PropertyName="ToOrder" /&gt;
              &lt;/CollectionViewSource.GroupDescriptions&gt;
          &lt;/CollectionViewSource&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid&gt;
          &lt;ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                    ItemsSource="{Binding Source={StaticResource ViewSource}}"&gt;
              &lt;ListView.GroupStyle&gt;
                  &lt;GroupStyle&gt;
                      &lt;GroupStyle.ContainerStyle&gt;
                          &lt;Style TargetType="{x:Type GroupItem}"&gt;
                              &lt;Setter Property="Template"&gt;
                                  &lt;Setter.Value&gt;
                                      &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                          &lt;DockPanel&gt;
                                              &lt;Grid DockPanel.Dock="Bottom"&gt;
                                                  &lt;Grid.Resources&gt;
                                                      &lt;local:SumConverter x:Key="sumConverter" /&gt;
                                                  &lt;/Grid.Resources&gt;
                                                  &lt;Grid.RowDefinitions&gt;
                                                      &lt;RowDefinition/&gt;
                                                      &lt;RowDefinition/&gt;
                                                  &lt;/Grid.RowDefinitions&gt;
                                                  &lt;Grid.ColumnDefinitions&gt;
                                                      &lt;ColumnDefinition Width="{Binding ElementName=Col1, Path=ActualWidth}"/&gt;
                                                      &lt;ColumnDefinition Width="{Binding ElementName=Col2, Path=ActualWidth}"/&gt;
                                                      &lt;ColumnDefinition Width="{Binding ElementName=Col3, Path=ActualWidth}"/&gt;
                                                  &lt;/Grid.ColumnDefinitions&gt;
                                                  &lt;TextBlock Grid.Row="1"
                                                             Text="Sum: "
                                                             FontWeight="Bold" /&gt;
                                                  &lt;TextBlock Grid.Column="1"
                                                             Grid.Row="1"
                                                             Text="{Binding Path=Items, Converter={StaticResource sumConverter}, ConverterParameter=1}"/&gt;
                                                  &lt;TextBlock Grid.Column="2"
                                                             Grid.Row="1"
                                                             Text="{Binding Path=Items, Converter={StaticResource sumConverter}, ConverterParameter=2}"/&gt;
                                                  &lt;Line Grid.Column="0"
                                                        Grid.Row="0"
                                                        Grid.ColumnSpan="3"
                                                        Stroke="Black"
                                                        X2="500"
                                                        Fill="Black"
                                                        VerticalAlignment="Center" /&gt;
                                              &lt;/Grid&gt;
                                              &lt;ItemsPresenter /&gt;
                                          &lt;/DockPanel&gt;
                                      &lt;/ControlTemplate&gt;
                                  &lt;/Setter.Value&gt;
                              &lt;/Setter&gt;
                          &lt;/Style&gt;
                      &lt;/GroupStyle.ContainerStyle&gt;
                  &lt;/GroupStyle&gt;
              &lt;/ListView.GroupStyle&gt;
              &lt;ListView.View&gt;
                  &lt;GridView x:Name="OverviewGridView"&gt;
                      &lt;GridViewColumn DisplayMemberBinding="{Binding Date, StringFormat=dd.MM.yyyy}"
                                      Header="Date" 
                                      x:Name="Col1"/&gt;
                      &lt;GridViewColumn DisplayMemberBinding="{Binding LicenseCount}"
                                      Header="Licenses" 
                                      x:Name="Col2"/&gt;
                      &lt;GridViewColumn DisplayMemberBinding="{Binding ScansCount}"
                                      Header="Scans" 
                                      x:Name="Col3"/&gt;
                  &lt;/GridView&gt;
              &lt;/ListView.View&gt;
          &lt;/ListView&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>ViewModel<br></p>
  
  <pre><code>namespace WpfApp2
  {
      using System;
      using System.Collections.ObjectModel;
      using System.ComponentModel;
      using System.Linq;
      using System.Runtime.CompilerServices;
      using WpfApp2.Annotations;
  
      public class OverView
      {
          public int ToGroup { get; set; } = 1;
          public DateTime Date { get; set; }
          public int LicenseCount { get; set; }
          public int ScansCount { get; set; }
      }
  
      public class ViewModel : INotifyPropertyChanged
      {
          private int _totalLicenses;
          private ObservableCollection&lt;OverView&gt; _dataList;
          private int _totalScans;
  
          public ViewModel()
          {
              OverView a = new OverView
                               {
                                   Date = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)),
                                   LicenseCount = 2,
                                   ScansCount = 7
                               };
              OverView b = new OverView
                               {
                                   Date = DateTime.Now.Subtract(new TimeSpan(5, 0, 0, 0)),
                                   LicenseCount = 3,
                                   ScansCount = 2
                               };
              OverView c = new OverView { Date = DateTime.Now, LicenseCount = 5, ScansCount = 4 };
              OverView d = new OverView
                               {
                                   Date = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)),
                                   LicenseCount = 1,
                                   ScansCount = 3
                               };
  
              DataList = new ObservableCollection&lt;OverView&gt; { a, b, c, d };
  
              TotalLicenses = DataList.Sum(overview =&gt; overview.LicenseCount);
              TotalScans = DataList.Sum(overview =&gt; overview.ScansCount);
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
          public ObservableCollection&lt;OverView&gt; DataList
          {
              get =&gt; _dataList;
              set
              {
                  _dataList = value;
                  OnPropertyChanged();
              }
          }
          public int TotalLicenses
          {
              get =&gt; _totalLicenses;
              set
              {
                  _totalLicenses = value;
                  OnPropertyChanged();
              }
          }
          public int TotalScans
          {
              get =&gt; _totalScans;
              set
              {
                  _totalScans = value;
                  OnPropertyChanged();
              }
          }
          [NotifyPropertyChangedInvocator]
          protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) =&gt;
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
      }
  }
  </code></pre>
  
  <p>SumConverter<br></p>
  
  <pre><code>namespace WpfApp2
  {
      #region Using
  
      using System;
      using System.Collections.Generic;
      using System.Globalization;
      using System.Windows.Data;
  
      #endregion
  
      public class SumConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          {
              int sum = 0;
              if (value is IEnumerable&lt;object&gt; total)
              {
                  foreach (object o in total)
                  {
                      if (o is OverView overview)
                      {
                          int col = int.Parse((string)parameter);
  
                          sum += col == 1 ? overview.LicenseCount : overview.ScansCount;
                      }
                  }
  
                  return sum;
              }
  
              return 0;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =&gt; 1;
      }
  }
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p>Edit, after further test, I had kind of success creating a new Property in the Overview object to group by it, then use a converter to sum the columns I need.
  This is the result: The code is updated with the solution.
  <a href="https://i.stack.imgur.com/3ZK6o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3ZK6o.png" alt="enter image description here"></a></p>