If anyone cares I have managed to get this to work....
I thought I would share the code...if there is a better way I would love to hear about it...pleases remember this is just a rough draft and I plan to tweak this alot but it should help others get started if they want to do this.
// report1.Total_sum and report1.Group_Sum are String Lists that have the exact field names from the database that I want to make group sums and
// total sum for (I copied alot of the xaml code from the StatFunction demo that Xceed provides)
int i1=0;
foreach (String s11 in report1.Total_Sum)
{
Xceed.Wpf.DataGrid.Stats.SumFunction sumfunc1 = new Xceed.Wpf.DataGrid.Stats.SumFunction();
//sumfunc1.SourcePropertyName = "Total_Sum_Source_" + s11 + i1.ToString();
sumfunc1.SourcePropertyName = s11;
sumfunc1.ResultPropertyName = "Total_Sum_Result_" + s11 + "__" + i1.ToString();
((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Add(sumfunc1);
i1++;
}
i1 = 0;
foreach (String s11 in report1.Group_Sum)
{
Xceed.Wpf.DataGrid.Stats.SumFunction sumfunc1 = new Xceed.Wpf.DataGrid.Stats.SumFunction();
//sumfunc1.SourcePropertyName = "Group_Sum_Source_" + s11 + i1.ToString();
sumfunc1.SourcePropertyName = s11;
sumfunc1.ResultPropertyName = "Group_Sum_Result_" + s11 + "__" + i1.ToString();
((Xceed.Wpf.DataGrid.DataGridCollectionView)dataGridControl1.ItemsSource).StatFunctions.Add(sumfunc1);
i1++;
}
// I then need to make a ResourceDictionary in code as a string
private void Create_ResourceDictionary_For_Stat_Functions_TableView()
{
if ((report1.Total_Sum.Count < 1) && (report1.Group_Sum.Count < 1))
return;
String s1;
s1 = "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:xcdg=\"http://schemas.xceed.com/wpf/xaml/datagrid\">";
//This StatCell Style will display, above the result, a line or a double line depending on whether the StatCell is in a group or not. -->
s1 += "<Style x:Key=\"tableViewTotalStatCellStyle\" TargetType=\"xcdg:StatCell\">";
//The line(s) will be of the same color as the HorizontalGridLine. -->
s1 += "<Setter Property=\"BorderBrush\" Value=\"{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).HorizontalGridLineBrush}\"/>";
s1 += "<Setter Property=\"Template\">";
s1 += "<Setter.Value>";
s1 += "<ControlTemplate TargetType=\"xcdg:StatCell\">";
s1 += "<Border Background=\"{TemplateBinding Background}\" BorderBrush=\"{TemplateBinding BorderBrush}\" BorderThickness=\"{TemplateBinding BorderThickness}\" Padding=\"{TemplateBinding Padding}\">";
s1 += "<StackPanel>";
s1 += "<Border x:Name=\"totalBorder\" BorderBrush=\"{TemplateBinding BorderBrush}\" BorderThickness=\"0,1,0,0\"/>";
s1 += "<ContentPresenter Content=\"{xcdg:CellContentBinding}\" ContentTemplate=\"{TemplateBinding ContentTemplate}\" ContentTemplateSelector=\"{TemplateBinding ContentTemplateSelector}\" HorizontalAlignment=\"{TemplateBinding HorizontalContentAlignment}\" VerticalAlignment=\"{TemplateBinding VerticalContentAlignment}\" />";
s1 += "</StackPanel>";
s1 += "</Border>";
s1 += "<ControlTemplate.Triggers>";
s1 += "<DataTrigger Binding=\"{Binding RelativeSource={RelativeSource Self}, Path=ParentColumn.Visible}\" Value=\"False\">";
s1 += "<Setter Property=\"Visibility\" Value=\"Collapsed\"/>";
s1 += "</DataTrigger>";
// <!-- When the StatCell is not inside a Group, display a double line. -->
s1 += "<Trigger Property=\"xcdg:GroupLevelIndicatorPane.GroupLevel\" Value=\"-1\">";
s1 += "<Setter TargetName=\"totalBorder\" Property=\"BorderThickness\" Value=\"0,1,0,1\"/>";
s1 += "<Setter TargetName=\"totalBorder\" Property=\"Padding\" Value=\"0,2,0,0\"/>";
s1 += "</Trigger>";
// <!-- When the StatCell has no content, don't display any line above. -->
s1 += "<Trigger Property=\"HasContent\" Value=\"False\">";
s1 += "<Setter TargetName=\"totalBorder\" Property=\"BorderThickness\" Value=\"0\"/>";
s1 += "</Trigger>";
s1 += "</ControlTemplate.Triggers>";
s1 += "</ControlTemplate>";
s1 += "</Setter.Value>";
s1 += "</Setter>";
s1 += "</Style>";
// StatFunction results can be "fetched" in any content control by using a
// binding on the StatContext property. This StatContext exposes, as properties,
// all the StatFunctions declared in the DataGridCollectionViewSource.
// This template will be added to the TableView in code. -->
/*
s1 += "<DataTemplate x:Key=\"tableViewHeader1\">";
s1 += "<Border Margin=\"4\"";
s1 += "TextElement.FontSize=\"14\"";
s1 += "TextElement.FontWeight=\"Bold\">";
s1 += "<StackPanel Orientation=\"Horizontal\" ToolTip=\"Only products that have a reorder level of 5, 10, 15, or 20, and units on order of 0 will be counted.">
<TextBlock TextWrapping="Wrap"
Text="Number of products to reorder : "/>
<TextBlock Text="{Binding RelativeSource={RelativeSource Self},Path=(xcdg:DataGridControl.StatContext).CountProductsToOrder}"/>
</StackPanel>
</Border>
</DataTemplate>*/
// <!-- A GroupConfiguration allows you to control the content (headers/footers)
// and behavior of same-level groups.
// This GroupConfiguration will be added to the TableView in code and will
// dictate the behavior and content of the groups. -->
int i1 = 0;
if(report1.Group_Sum.Count >0)
{
s1 += "<xcdg:GroupConfiguration x:Key=\"tableViewGroupConfiguration1\">";
s1 += "<xcdg:GroupConfiguration.Footers>";
//<!-- The groups will contain a StatRow visible even when the group is collapsed. -->
s1 += "<xcdg:GroupHeaderFooterItemTemplate VisibleWhenCollapsed=\"True\">";
s1 += "<DataTemplate>";
s1 += "<xcdg:StatRow>";
foreach(String s111 in report1.Group_Sum)
{
//<!-- The following three cells simply refer to the previously declared StatFunctions using the ResultPropertyName property. -->
// sumfunc1.SourcePropertyName = "Group_Sum_Source_" + report1.Group_Sum[i1] + i1.ToString();
// sumfunc1.ResultPropertyName = "Group_Sum_Result_" + report1.Group_Sum[i1] + i1.ToString();
s1 += "<xcdg:StatCell FieldName=\"" + s111 + "\" ResultPropertyName=\"" +"Group_Sum_Result_" + report1.Group_Sum[i1] + "__" + i1.ToString() + "\" Style=\"{StaticResource tableViewTotalStatCellStyle}\"/>";
i1++;
}
s1 += "</xcdg:StatRow>";
s1 += "</DataTemplate>";
s1 += "</xcdg:GroupHeaderFooterItemTemplate>";
s1 += "</xcdg:GroupConfiguration.Footers>";
s1 += "</xcdg:GroupConfiguration>";
}
i1 = 0;
if(report1.Total_Sum.Count >0)
{
// <!-- This template will be added to the TableView in code. -->
s1 += "<DataTemplate x:Key=\"tableViewFixedFooter1\">";
s1 += "<xcdg:StatRow>";
s1 += "<xcdg:StatRow.Resources>";
s1 += "<Style TargetType=\"xcdg:StatCell\" BasedOn=\"{StaticResource tableViewTotalStatCellStyle}\"/>";
s1 += "</xcdg:StatRow.Resources>";
// <!-- Each StatCell has a default StatResultConverter assigned to it,
// allowing only a ConverterParameter that will format
// the result to be specified. To improve its usage in XAML, the StatResultConverter's
// parameter supports a simplified syntax of composite formatting.
// Refer to the documentation for more informations. -->
foreach(String s111 in report1.Total_Sum)
{
s1 += "<xcdg:StatCell FieldName=\"" + s111 + "\" ResultPropertyName=\"" +"Total_Sum_Result_" + report1.Total_Sum[i1] + "__" + i1.ToString() + "\" Style=\"{StaticResource tableViewTotalStatCellStyle}\"/>";
//s1 += "<xcdg:StatCell FieldName=\"UnitsInStock\" ResultPropertyName=\"SumOfUnitsInStock\"/>";
i1++;
}
s1 += "</xcdg:StatRow>";
s1 += "</DataTemplate>";
s1 += "</ResourceDictionary>";
}
// This is how I load the new resource dictionary I just made
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(s1));
ResourceDictionary rd = null;
rd = (ResourceDictionary)XamlReader.Load(stream);
Application.Current.Resources = rd;
//Application.Current.Resources.Clear();
}
// And now use this new resource dictionary.....you need to add it like this...
if(report1.Total_Sum.Count > 0)
dataGridControl1.View.FixedFooters.Add( ( DataTemplate )this.FindResource( "tableViewFixedFooter1" ) );
if(report1.Group_Sum.Count > 0)
dataGridControl1.DefaultGroupConfiguration = ( GroupConfiguration )this.FindResource( "tableViewGroupConfiguration1" );