First off, I apologize, this was meant for the WPF forum, but I posted too quickly. Please move it if you need to.
I am using some of the DataAnnotations attributes, and they work wonderfully. My hope was to set which properties would aggregate with a format string with a custom attribute. Something like below.
[Display(Name =
"Trade Amount"
)]
[DisplayFormat(DataFormatString =
"{0:C}"
)]
[DisplayAggregate(AggregateFunction.Sum, ResultFormatString =
"Total: {0:C}"
)]
[DisplayAggregate(AggregateFunction.Min, ResultFormatString =
"Min: {0:C}"
)]
public
double
Amount {
get
;
set
; }
I actually got this working after posting, but it is a bit of a workaround. In the AutoGeneratingColumn event, I match the column name against the RadGridView item and pull the attributes from there, not the column.datatype. But if there is a more elegant solution, I wouldn't mind changing my existing work.
Cheers.
private
void
ResultsGridView_OnAutoGeneratingColumn(
object
sender, GridViewAutoGeneratingColumnEventArgs e)
{
var column = e.Column
as
GridViewDataColumn;
if
(column ==
null
|| ResultsGridView.Items.Count == 0)
return
;
var propName = column.DataMemberBinding.Path.Path;
var props = ResultsGridView.Items[0].GetType().GetProperties();
var aggregates = (from prop
in
props where prop.Name == propName select (DisplayAggregate[]) prop.GetCustomAttributes(
typeof
(DisplayAggregate),
false
)).FirstOrDefault();
AddAggregatesToGridColumn(aggregates, column);
}