Does RadChart support anonymous types?

6 posts, 0 answers
  1. Chris
    Chris avatar
    2 posts
    Member since:
    Aug 2012

    Posted 09 Aug 2012 Link to this post

    Title says it all: is the RadChart supposed to support anonymous types?

    I was test driving some of the Telerik controls and kept getting the exception at the end of this post. This exception was captured both by the Visual Studio designer and at runtime. As soon as I replaced the anonymous type with a nested class the exception went away.





    System.TypeAccessException was unhandled
      Message=Attempt by method 'DynamicClass.Telerik_DynamicGetter_Distance(System.Object)' to access type '<>f__AnonymousType0`4<System.Double,System.Double,System.Double,System.Double>' failed.
      Source=Anonymously Hosted DynamicMethods Assembly
      TypeName=""
      StackTrace:
           at Telerik_DynamicGetter_Distance(Object )
           at Telerik.Windows.Controls.ChartView.PropertyNameDataPointBinding.GetValue(Object instance) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\PropertyNameDataPointBinding.cs:line 97
           at Telerik.Windows.Controls.ChartView.ScatterSeriesDataSource.InitializeBinding(DataPointBindingEntry binding) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\DataSources\ScatterSeriesDataSource.cs:line 114
           at Telerik.Windows.Controls.ChartView.ChartSeriesDataSource.GenerateDataPoint(Object dataItem, Int32 index) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\DataSources\ChartSeriesDataSource.cs:line 145
           at Telerik.Windows.Controls.ChartView.ChartSeriesDataSource.BindCore() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\DataSources\ChartSeriesDataSource.cs:line 104
           at Telerik.Windows.Controls.ChartView.ChartSeriesDataSource.Bind() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\DataSources\ChartSeriesDataSource.cs:line 234
           at Telerik.Windows.Controls.ChartView.ChartSeriesDataSource.Rebind(Boolean itemsSourceChanged, IEnumerable newSource) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\DataSources\ChartSeriesDataSource.cs:line 80
           at Telerik.Windows.Controls.ChartView.ChartSeriesDataSource.set_ItemsSource(IEnumerable value) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\DataBinding\DataSources\ChartSeriesDataSource.cs:line 53
           at Telerik.Windows.Controls.ChartView.ChartSeries.InitDataBinding() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\Common\ChartSeries.cs:line 309
           at Telerik.Windows.Controls.ChartView.ScatterPointSeries.InitDataBinding() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\CartesianChart\Series\Scatter\ScatterPointSeries.cs:line 152
           at Telerik.Windows.Controls.ChartView.ChartSeries.OnApplyTemplate() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\Common\ChartSeries.cs:line 238
           at Telerik.Windows.Controls.ChartView.PointTemplateSeries.OnApplyTemplate() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\Common\PointTemplateSeries.cs:line 164
           at Telerik.Windows.Controls.ChartView.ScatterLineSeries.OnApplyTemplate() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\CartesianChart\Series\Scatter\ScatterLineSeries.cs:line 140
           at System.Windows.FrameworkElement.ApplyTemplate()
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Border.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.Controls.Control.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
           at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
           at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
           at System.Windows.UIElement.Measure(Size availableSize)
           at System.Windows.ContextLayoutManager.UpdateLayout()
           at System.Windows.UIElement.UpdateLayout()
           at System.Windows.Controls.TabItem.OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
           at System.Windows.UIElement.OnPreviewGotKeyboardFocusThunk(Object sender, KeyboardFocusChangedEventArgs e)
           at System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
           at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
           at System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)
           at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
           at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
           at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
           at System.Windows.Input.InputManager.ProcessStagingArea()
           at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
           at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
           at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
           at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
           at System.Windows.Input.Keyboard.Focus(IInputElement element)
           at System.Windows.UIElement.Focus()
           at System.Windows.Controls.TabItem.SetFocus()
           at System.Windows.Controls.TabItem.OnMouseLeftButtonDown(MouseButtonEventArgs e)
           at System.Windows.UIElement.OnMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e)
           at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
           at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
           at System.Windows.EventRoute.ReInvokeHandlers(Object source, RoutedEventArgs args)
           at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
           at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
           at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
           at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
           at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
           at System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)
           at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
           at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
           at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
           at System.Windows.Input.InputManager.ProcessStagingArea()
           at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
           at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
           at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
           at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs)
           at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.Run()
           at System.Windows.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at ChartingComparison.App.Main() in C:\Users\Chris\Documents\Visual Studio 2010\Projects\WpfGraph\ChartingComparison\obj\x86\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 

  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 14 Aug 2012 Link to this post

    Hi Chris,

    Please, find attached a small example, showing how to bind RadChartView to a list of anonymous objects. It is based on this blog post i.e. the BarSeries needs understanding of the type of objects it is bound to.

    Just a small clarification -- I have moved this thread to the ChartView forum as this is the control you have chosen and actually this would be our recommendation. You can find more information here -- RadChart vs RadChartView.

    Best regards,
    Ves
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    2 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Hi Ves,

    Thanks for the example. It turns out that the problem lies in your PropertyNameDataPointBinding. By replacing the GenericDataPointBinding instances from your example I was able to reproduce my issue.

    Is this a bug or functionality that will be added to the PropertyNameDataPointBinding in the future? As xaml can only instantiate instances of type PropertyNameDataPointBinding this would be a large convenience.

    I fail to see a technical issue with anonymous types as reflection works just as well on anonymous types as any other as can be demonstrated by the following example:

    var query = from i in Enumerable.Range(0, 10)
                select new { Value = i * i };
     
    var property = query.First().GetType().GetProperties().Single(x => x.Name == "Value");
     
    foreach (var instance in query)
    {
        MessageBox.Show(property.GetValue(instance, null).ToString());
    }

  5. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 17 Aug 2012 Link to this post

    Hi Chris,

    Thanks for the feedback. I will make sure it is considered with the appropriate attention, but I am afraid you will have to stick with the code-behind approach and GenericDataPointBinding for the moment.

    Best regards,
    Ves
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Greg
    Greg avatar
    29 posts
    Member since:
    Oct 2007

    Posted 13 Mar 2013 Link to this post

    Has any progress been made on this issue? It is extremely desirable to bind Chartview to LINQ-derived anonymous types.
  7. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 18 Mar 2013 Link to this post

    Hi Greg,

    I am afraid we have no updates on the matter. Actually, there are two easy workarounds -- either use GenericDataPointBinding as described above or add a simple class definition with one or two properties -- the ones used by the chart -- so that you still bind to linq derived type, it's just that this type will not be anonymous.

    Best regards,
    Ves
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready