Hi,
I have an unbound field that I want to show the sum of it in the footer, but it shows it as 0.00.
Unbound Field:
<dataPresenter:UnboundField x:Name="txt_amt" Name="amt" Label="" DataType="{x:Type system:Int32}"><dataPresenter:Field.Settings><dataPresenter:FieldSettings AllowSummaries="True"><dataPresenter:FieldSettings.CellValuePresenterStyle><Style TargetType="{x:Type dataPresenter:CellValuePresenter}" BasedOn="{StaticResource {x:Type dataPresenter:CellValuePresenter}}"><Setter Property="Template"><Setter.Value><ControlTemplate><Grid><TextBoxText="{Binding DataItem.amt, StringFormat={}{0:N2}}" /></Grid></ControlTemplate></Setter.Value></Setter></Style></dataPresenter:FieldSettings.CellValuePresenterStyle></dataPresenter:FieldSettings></dataPresenter:Field.Settings></dataPresenter:UnboundField>
And in definition:
<dataPresenter:FieldLayout.SummaryDefinitions><dataPresenter:SummaryDefinition SourceFieldName="amt" Calculator="Sum" StringFormat="{}{0:N2}"/></dataPresenter:FieldLayout.SummaryDefinitions>
Thanks
Hello Shab,
I have been investigating into the behavior you are seeing, and the reason for this is because the value that is shown in the CellValuePresenter’s Template is not the actual underlying Cell value. With an UnboundField, you need to set this as demonstrated in the following online documentation article: https://www.infragistics.com/help/wpf/xamdatapresenter-add-unbound-fields-to-a-datapresenter-control.
The part I am unsure of in this case is why you are using an UnboundField? The reason I ask is because it appears that you are simply binding to a property that exists on the DataItem, and so you should be able to just define a Field like so:
<Field Name=”amt” />
This will create a “bound” field to your “amt” property on your data item and the summaries will work without the need to manually handle the cell values.
Please let me know if you have any other questions or concerns on this matter.
Thanks for the reply. Field works, but I didnt understand what I need to set for UnboundField's cell value to work, could you point me to it or if not a big ask give an example. Thanks
The documentation article I linked above contains a code-example of what you need to do to get the cell value to work. About halfway down the page, there is both a C# and VB code-snippet that handles the InitializeRecord event of the XamDataGrid. It then casts the e.Record (where ‘e’ is the event arguments) to a DataRecord, gets the UnboundField cells from the Cells collection of the record and sets the Value.