I have created a custom row summary calculator but do not know how to attach it to a field in the xamDataGrid. I build it and register it in code and then reference it in the xaml as follows:
<igDP:SummaryDefinition
StringFormat=" {0:#,##0.00;(#,##0.00);0.0}"
Key="WorkUnitLaborMult"
SourceFieldName="WorkUnitLaborMult"
Calculator="ProjectEffectiveMult" Position="UseSummaryPositionField"/>
The summary comes up blank when the grid is displayed. Using the debugger I can tell it is not running through the custom calculation class code.
Thank you for your help.
So I figured out that once I register the SummaryCalculator by running through the code that registers, it does not display a value during this first processing. If I exit back to the Project Selection and select the project again, the summary calculation is performed because I did not UnRegister the calculator.
I thought I would prgrammatically set the SummaryCalculator, after registering it, using SummaryCalculator.RegisteredCalculators, so it would be available immediately. However I could not find a way to get a reference to any specific Registered Summary Calculator no less the summary calculator I registered.
The example in the documentation makes it available to be selected but I can't let the users choose the calculations for specific fields I want to set them in xaml or using code. I am going to have to do more of these so some help would be nice.
Thank You.
I did two things in the source code the last time I did this.
1. Register the calculator:
SummaryCalculator.Register(new MyCalculatorClass());
2. Create a property for the calculator.
public static MyCalculatorClass MyCalculatorProperty { get { if (null == _classObject) _classObject= new MyCalculatorClass();
return _classObject; } }
3. In the XAML, I bound the summary field to the property name MyCalculatorProperty, not the class name of the calculator.
There may be other ways of doing this, but that is how I did it.
Thank you for your response. Can I see the xaml you used to do the binding? Here is my xaml:
OLD CODE
<!-- <igDP:SummaryDefinition
Calculator="ProjectEffectiveMult" Position="UseSummaryPositionField"/> -->
USING YOUR METHOD
SourceFieldName="myProjectEffectiveMult"
Position="UseSummaryPositionField"/>
Hello:
I've followed the following to create a custom summary calculator:
http://community.infragistics.com/wpf/wiki/creating-a-custom-summary-for-the-xamdatagrid/1.aspx
http://help.infragistics.com/Help/Doc/WPF/2013.2/CLR4.0/html/xamDataPresenter_Creating_a_Custom_Summary_Calculator.html
and created a trivial custom calculator. I had the same issue as originally stated in this thread. The calculation will only work on the second invocation.
I followed the static property approach suggested by enderrpf and it works, is this the preferred mechanism?
Not working the first time (bind to class) :
<calculators:MySummaryCalculator x:Key="MySummaryCalculator" />
<igDP:SummaryDefinition SourceFieldName="Total" Calculator="MySummaryCalculator" />
MySummaryCalculator.cs:
public override string Name{ get { return "MySummaryCalculator"; }}
Working (bind to static property):
<igDP:SummaryDefinition SourceFieldName="Total" Calculator="{x:Static calculators:MySummaryCalculator.Addition}" />
public static MySummaryCalculator Addition{ get { return _mySummaryCalculator ?? new MySummaryCalculator(); }}
To register in the view.cs;
private void ViewLoaded(object sender, RoutedEventArgs e){ SummaryCalculator.Register(new MySummaryCalculator());}
Thx
Hello Rajib,
You can register your summary calculator in the constructor of the App class, in the App.xaml.cs file.
What is the right place to register SummaryCalculator and declare its static property if we are using MVVM/PRISM?
I set a couple of breakpoints. One in the get property that I set up, and one in the BeginCalculation function of the calculator class. I was able to jump into both of those without any problems.
SummaryDefinition:<igDP:SummaryDefinition Key="PerUnit" SourceFieldName="PerUnit" Calculator="{x:Static Pages:BasePositionPage.MyCalculatorProperty}" StringFormat="{}{0:C}"/>
FieldDefinition:<igDP:UnboundField Name="PerUnit" Label="Unit Cost" Column="15" DataType="{x:Type sys:Decimal}" BindingPath="UnitCost" BindingMode="OneWay"></igDP:UnboundField>