title: How do I add a footer row in a WPF datagrid?
body: <p>How Do I Add a footer row in WPF datagrid? I had to add a row in a WPF datagrid for the sum of each column, I don't want to use any dll or telerik and some things like that only use Microsoft components to do this. I'm trying to do it this way:</p>
  <pre class="lang-xaml prettyprint-override"><code>&lt;Style TargetType=&quot;{x:Type DataGrid}&quot;&gt;
      &lt;Setter Property=&quot;Foreground&quot;
      Value=&quot;{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}&quot; /&gt;
      &lt;Setter Property=&quot;BorderBrush&quot;&gt;
          &lt;Setter.Value&gt;
              &lt;LinearGradientBrush EndPoint=&quot;0.5,1&quot; StartPoint=&quot;0.5,0&quot;&gt;
                  &lt;GradientStop Color=&quot;{DynamicResource BorderLightColor}&quot; Offset=&quot;0&quot; /&gt;
                  &lt;GradientStop Color=&quot;{DynamicResource BorderDarkColor}&quot; Offset=&quot;1&quot; /&gt;
              &lt;/LinearGradientBrush&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;1&quot; /&gt;
      &lt;Setter Property=&quot;RowDetailsVisibilityMode&quot; Value=&quot;VisibleWhenSelected&quot; /&gt;
      &lt;Setter Property=&quot;ScrollViewer.CanContentScroll&quot; Value=&quot;true&quot; /&gt;
      &lt;Setter Property=&quot;ScrollViewer.PanningMode&quot; Value=&quot;Both&quot; /&gt;
      &lt;Setter Property=&quot;Stylus.IsFlicksEnabled&quot; Value=&quot;False&quot; /&gt;
      &lt;Setter Property=&quot;Template&quot;&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType=&quot;{x:Type DataGrid}&quot;&gt;
                  &lt;Border x:Name=&quot;border&quot;
          SnapsToDevicePixels=&quot;True&quot;
          BorderBrush=&quot;{TemplateBinding BorderBrush}&quot;
          BorderThickness=&quot;{TemplateBinding BorderThickness}&quot;
          Padding=&quot;{TemplateBinding Padding}&quot;&gt;
                      &lt;Border.Background&gt;
                          &lt;SolidColorBrush Color=&quot;{DynamicResource ControlLightColor}&quot; /&gt;
                      &lt;/Border.Background&gt;
                      &lt;VisualStateManager.VisualStateGroups&gt;
                          &lt;VisualStateGroup x:Name=&quot;CommonStates&quot;&gt;
                              &lt;VisualState x:Name=&quot;Disabled&quot;&gt;
                                  &lt;Storyboard&gt;
                                      &lt;ColorAnimationUsingKeyFrames Storyboard.TargetName=&quot;border&quot;
                                          Storyboard.TargetProperty=&quot;(Panel.Background).(SolidColorBrush.Color)&quot;&gt;
                                          &lt;EasingColorKeyFrame KeyTime=&quot;0&quot; Value=&quot;{DynamicResource ControlLightColor}&quot; /&gt;
                                      &lt;/ColorAnimationUsingKeyFrames&gt;
                                  &lt;/Storyboard&gt;
                              &lt;/VisualState&gt;
                              &lt;VisualState x:Name=&quot;Normal&quot; /&gt;
                          &lt;/VisualStateGroup&gt;
                      &lt;/VisualStateManager.VisualStateGroups&gt;
                      &lt;ScrollViewer x:Name=&quot;DG_ScrollViewer&quot; Focusable=&quot;false&quot; Background=&quot;Black&quot;&gt;
                          &lt;ScrollViewer.Template&gt;
                              &lt;ControlTemplate TargetType=&quot;{x:Type ScrollViewer}&quot;&gt;
                                  &lt;Grid&gt;
                                      &lt;Grid.ColumnDefinitions&gt;
                                          &lt;ColumnDefinition Width=&quot;Auto&quot; /&gt;
                                          &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
                                          &lt;ColumnDefinition Width=&quot;Auto&quot; /&gt;
                                      &lt;/Grid.ColumnDefinitions&gt;
                                      &lt;Grid.RowDefinitions&gt;
                                          &lt;RowDefinition Height=&quot;Auto&quot; /&gt;
                                          &lt;RowDefinition Height=&quot;*&quot; /&gt;
                                          &lt;RowDefinition Height=&quot;Auto&quot; /&gt;
                                          &lt;RowDefinition Height=&quot;Auto&quot; /&gt;
                                      &lt;/Grid.RowDefinitions&gt;
  
                                      &lt;Button Focusable=&quot;false&quot;
                                          Command=&quot;{x:Static DataGrid.SelectAllCommand}&quot;
                                          Style=&quot;{DynamicResource {ComponentResourceKey 
                                      ResourceId=DataGridSelectAllButtonStyle, 
                                      TypeInTargetAssembly={x:Type DataGrid}}}&quot;
                                          Visibility=&quot;{Binding HeadersVisibility, 
                                      ConverterParameter={x:Static DataGridHeadersVisibility.All}, 
                                      Converter={x:Static DataGrid.HeadersVisibilityConverter}, 
                                      RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}&quot;
                                          Width=&quot;{Binding CellsPanelHorizontalOffset, 
                                      RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}&quot; /&gt;
  
                                      &lt;DataGridColumnHeadersPresenter x:Name=&quot;PART_ColumnHeadersPresenter&quot;
                                              Grid.Column=&quot;1&quot;
                                              Visibility=&quot;{Binding HeadersVisibility, 
                  ConverterParameter={x:Static DataGridHeadersVisibility.Column}, 
                  Converter={x:Static DataGrid.HeadersVisibilityConverter}, 
                  RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}&quot; /&gt;
  
                                      &lt;ScrollContentPresenter x:Name=&quot;PART_ScrollContentPresenter&quot;
                                      Grid.ColumnSpan=&quot;2&quot;
                                      Grid.Row=&quot;1&quot;
                                      CanContentScroll=&quot;{TemplateBinding CanContentScroll}&quot; /&gt;
  
                                      &lt;ScrollBar x:Name=&quot;PART_VerticalScrollBar&quot;
                          Grid.Column=&quot;2&quot;
                          Grid.Row=&quot;1&quot;
                          Orientation=&quot;Vertical&quot;
                          ViewportSize=&quot;{TemplateBinding ViewportHeight}&quot;
                          Maximum=&quot;{TemplateBinding ScrollableHeight}&quot;
                          Visibility=&quot;{TemplateBinding ComputedVerticalScrollBarVisibility}&quot;
                          Value=&quot;{Binding VerticalOffset, Mode=OneWay, 
                              RelativeSource={RelativeSource TemplatedParent}}&quot;/&gt;
                                      &lt;TextBlock Grid.Row=&quot;2&quot; Grid.Column=&quot;1&quot; Text=&quot;This is footer!&quot;/&gt;
                                      &lt;Grid Grid.Column=&quot;1&quot; Grid.Row=&quot;3&quot;&gt;
                                          &lt;Grid.ColumnDefinitions&gt;
                                              &lt;ColumnDefinition Width=&quot;{Binding NonFrozenColumnsViewportHorizontalOffset, 
                      RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}&quot; /&gt;
                                              &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
                                          &lt;/Grid.ColumnDefinitions&gt;
  
                                          &lt;ScrollBar x:Name=&quot;PART_HorizontalScrollBar&quot;
                          Grid.Column=&quot;1&quot;
                          Orientation=&quot;Horizontal&quot;
                          ViewportSize=&quot;{TemplateBinding ViewportWidth}&quot;
                          Maximum=&quot;{TemplateBinding ScrollableWidth}&quot;
                          Visibility=&quot;{TemplateBinding ComputedHorizontalScrollBarVisibility}&quot;
                          Value=&quot;{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}&quot;/&gt;
                                      &lt;/Grid&gt;
                                  &lt;/Grid&gt;
                              &lt;/ControlTemplate&gt;
                          &lt;/ScrollViewer.Template&gt;
                          &lt;ItemsPresenter SnapsToDevicePixels=&quot;{TemplateBinding SnapsToDevicePixels}&quot; /&gt;
                      &lt;/ScrollViewer&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Style.Triggers&gt;
          &lt;Trigger Property=&quot;IsGrouping&quot; Value=&quot;true&quot;&gt;
              &lt;Setter Property=&quot;ScrollViewer.CanContentScroll&quot; Value=&quot;false&quot; /&gt;
          &lt;/Trigger&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>
  <p>I also tried adding a grid instead of textblock, but when resizing datagrid columns, they can't resize and looks very ugly.</p>