Hello,
I am using the RadGridView version 2012.2.607.40 for WPF and am having a heck of a time trying to determine how to write a custom aggregrate function to sum a column of System.TimeSpan values. My XAML definition of my grid view looks like this:
 
Please note that ScanSession.Duration is of type System.TimeSpan.
I first tried the naive approach of just using the <telerik:SumFunction/> as shown above and got an InvalidOperationException with the error:
No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
So I assumed I needed to write a custom aggregrate function and looked at the standard deviation example Telerik has and came up with substituting <local:TimeSpanSumFunction SourceField="ScanSession.Duration"/> for <telerik:SumFunction/> and added the following:
 
 
 
 
 
I then got an InvalidOperationException with the error:
No generic method 'TimeSpanSum' on type 'Exponent.Analyzer.Performance.Aggregates' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
Finally, I wondered if I could just extend EnumerableAggregateFunction so I changed the XAML to use simply <local:TimeSpanSumFunction/> and came up with:
 
 
 
 
 
and I still get an InvalidOperationException with the message:
No generic method 'TimeSpanSum' on type 'Exponent.Analyzer.Performance.Aggregates' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
Obviously, I do not know how to write a custom aggregate function and I am finding what little documentation there is very unhelpful. I have more custom aggregate functions I need to write using other non-simple types.
Could somebody please give me some advise on how to write these custom aggregate functions?
And one other thing, can you also suggest how I can invoke my TimeSpanConverter (as seen in the XAML for the "Elapsed TIme" grid column") when displaying the results of the aggregte function?
Thank you,
-- john
                                I am using the RadGridView version 2012.2.607.40 for WPF and am having a heck of a time trying to determine how to write a custom aggregrate function to sum a column of System.TimeSpan values. My XAML definition of my grid view looks like this:
<telerik:RadGridView x:Name="scanSessionList" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding ElementName=_this, Path=ScanSessions}" Margin="0,0,0,6" ShowGroupPanel="False" ShowGroupFooters="True">    <telerik:RadGridView.GroupDescriptors>        <telerik:GroupDescriptor Member="ScanSession.VehicleId" SortDirection="Ascending">            <telerik:GroupDescriptor.AggregateFunctions>                <telerik:CountFunction Caption="Missions: "/>            </telerik:GroupDescriptor.AggregateFunctions>        </telerik:GroupDescriptor>    </telerik:RadGridView.GroupDescriptors>    <telerik:RadGridView.Columns>        <telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Path=ScanSession.Tag}"/>        <telerik:GridViewDataColumn Header="Start Time" DataMemberBinding="{Binding Path=ScanSession.StartTimestamp, StringFormat=d MMM yyyy HH:mm}"/>        <telerik:GridViewDataColumn Header="Elapsed Time" DataMemberBinding="{Binding Path=ScanSession.Duration, Converter={StaticResource TimeSpanConverter}}">            <telerik:GridViewDataColumn.AggregateFunctions>                <telerik:SumFunction/>            </telerik:GridViewDataColumn.AggregateFunctions>        </telerik:GridViewDataColumn>        <telerik:GridViewDataColumn Header="Distance" DataMemberBinding="{Binding Path=ScanSession.DistanceTravelled, Converter={StaticResource DistanceConverter}}"/>        <telerik:GridViewDataColumn Header="Avg Speed" DataMemberBinding="{Binding Path=ScanSession.AverageSpeed, Converter={StaticResource SpeedConverter}}"/>        <telerik:GridViewDataColumn Header="Max Speed" DataMemberBinding="{Binding Path=ScanSession.MaximumSpeed, Converter={StaticResource SpeedConverter}}"/>    </telerik:RadGridView.Columns></telerik:RadGridView>Please note that ScanSession.Duration is of type System.TimeSpan.
I first tried the naive approach of just using the <telerik:SumFunction/> as shown above and got an InvalidOperationException with the error:
No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
So I assumed I needed to write a custom aggregrate function and looked at the standard deviation example Telerik has and came up with substituting <local:TimeSpanSumFunction SourceField="ScanSession.Duration"/> for <telerik:SumFunction/> and added the following:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Telerik.Windows.Data;namespace Exponent.Analyzer.Performance{    public class TimeSpanSumFunction : EnumerableSelectorAggregateFunction    {        protected override string AggregateMethodName        {            get { return "TimeSpanSum"; }        }        protected override Type ExtensionMethodsType        {            get { return typeof(Aggregates); }        }    }    public static class Aggregates    {        public static TimeSpan TimeSpanSum<TSource>(IEnumerable<TSource> source, Func<TSource, TimeSpan> selector)        {            TimeSpan sum = TimeSpan.FromSeconds(0);            foreach (TimeSpan ts in source.Select(s => selector(s)))            {                sum = sum.Add(ts);            }            return sum;        }    }}I then got an InvalidOperationException with the error:
No generic method 'TimeSpanSum' on type 'Exponent.Analyzer.Performance.Aggregates' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
Finally, I wondered if I could just extend EnumerableAggregateFunction so I changed the XAML to use simply <local:TimeSpanSumFunction/> and came up with:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Telerik.Windows.Data;namespace Exponent.Analyzer.Performance{    public class TimeSpanSumFunction : EnumerableAggregateFunction    {        protected override string AggregateMethodName        {            get { return "TimeSpanSum"; }        }        protected override Type ExtensionMethodsType        {            get { return typeof(Aggregates); }        }    }    public static class Aggregates    {        public static TimeSpan TimeSpanSum<TSource>(IEnumerable<TimeSpan> source)        {            TimeSpan sum = TimeSpan.FromSeconds(0);            foreach (TimeSpan ts in source)            {                sum = sum.Add(ts);            }            return sum;        }    }}and I still get an InvalidOperationException with the message:
No generic method 'TimeSpanSum' on type 'Exponent.Analyzer.Performance.Aggregates' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
Obviously, I do not know how to write a custom aggregate function and I am finding what little documentation there is very unhelpful. I have more custom aggregate functions I need to write using other non-simple types.
Could somebody please give me some advise on how to write these custom aggregate functions?
And one other thing, can you also suggest how I can invoke my TimeSpanConverter (as seen in the XAML for the "Elapsed TIme" grid column") when displaying the results of the aggregte function?
Thank you,
-- john

