Gets the context from which a statistical function retrieves the values needed to calculate its result, and that exposes the results as properties that have the same names as the functions' ResultPropertyName properties.
The element whose statistical context to retrieve.
Return Value
An object representing the context from which a statistical function retrieves the values needed to calculate its result, and that exposes the results as properties that have the same names as the functions' ResultPropertyName properties.
Remarks
The values used to calculate the results of a statistical function are retrieved from its statistical context. For example, if an element that displays the results of a statistical function is contained in a group footer, the element's statistical context will be the group, and the results of the statistical function will be calculated according to the values of the data items in the group. If the same element is placed in the footers of a grid, then its statistical context is provided by a grid (through the StatContext property) and all the data items will be used to calculate the results.
The same statistical function can be used by more than one element, regardless of the statistical context. For example, if the average of a column is to be displayed in both the footers of a group and a grid, only one AverageFunction needs to be added to the StatFunctions collection.
Example
All examples in this topic assume that the grid is bound to the OrderDetails table of the Northwind database, unless stated otherwise.
The following example demonstrates how to display the results of various statistical functions in and outside of a grid.The following example demonstrates how to change the statistical context of a TextBlock that displays the results of a statistical function when the current item is changed. The statistical context of the TextBlock will be changed in the grid's PropertyChanged event handler by using the GetParentGroupFromItem method to retrieve the current group and set it as the new statistical context.
To simplify the code below, the DataContext of the StackPanel could have been modified rather than the DataContext of each TextBlock.
The implementation of the PropertyChanged event handler is located below.The following code provides the implementation of the PropertyChanged event handler.The following code provides the implementation of the PropertyChanged event handler.The following example demonstrates how to create a custom data template that will be used in the footers of the first-level groups to display the results of various statistical functions.
Target Platforms: Windows 11, Windows, 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2