dynamic object / expandoobject bind to itemsource?

2 posts, 0 answers
  1. Tony
    Tony avatar
    6 posts
    Member since:
    Sep 2011

    Posted 29 May 2012 Link to this post

    I tried to bind  dynamic list like below but failed.

     

    ObservableCollection<dynamic>       cases     
     mapping.ItemsSource = cases     ;


    mapping.ItemMappings.Add(new ItemMapping(this.YValue, DataPointMember.YValue));


    It seems something wrong with the seriesmapping?
    Is it possible to bind a dynamic object list to a line chart or bar chart?

    P.S
    I use linq to query the dynamic objects
    IEnumerable<dynamic> callStats = (from c in ipCases
                                group c by c.Year into d
                                select new
                                {
                                    Year = Convert.ToInt32(d.Key.ToString()),
                                    CaseCounts = d.Sum(x => x.CaseCount)
                                } as dynamic);


    Thanks!
  2. Rosko
    Admin
    Rosko avatar
    137 posts

    Posted 01 Jun 2012 Link to this post

    Hi Tony,

    We investigated closely the scenario. The problem is caused by the security model of the Silverlight platform. RadChart is not expected to work under these cirumstances. The UI control does not have access to the object, because of the Silverlight security restrictions. You can read about the topic over here. There is a possible workaround for this. You can create another class to which you will bind to the RadChart. You just need to cast the result of the LINQ query to that object. You can see the code snippet for further help.

    public class HelperType
            {
                public int Year { get; set; }
                public int CaseCounts { get; set; }
            }

    IEnumerable<dynamic> callStats = (from c in ipCases
                                                  group c by c.Year into d
                                                  select new HelperType
                                                  {
                                                      Year = Convert.ToInt32(d.Key.ToString()),
                                                      CaseCounts = d.Sum(x => x.CaseCount)
                                                  });

    Greetings,
    Rosko
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top