Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1775
Using DynamicDictionary as ItemsSource
posted

Good afternoon.
Using a class DynamicDictionary as ItemsSource.

    public class DynamicDictionary: DynamicObject
     {
         Dictionary <string, object> dictionary
             = New Dictionary <string, object> ();
  
         public override bool TryGetMember (
             GetMemberBinder binder, out object result)
         {
             string name = binder.Name.ToLower ();
             return dictionary.TryGetValue (name, out result);
         }

 
         public override bool TrySetMember (
             SetMemberBinder binder, object value)
         {
             dictionary [binder.Name.ToLower ()] = value;
             return true;
         }

         public override IEnumerable <string> GetDynamicMemberNames ()
         {
             return dictionary.Keys;
         }

     }

DynamicDictionary use as follows:

             List <DynamicDictionary> rows = new List <DynamicDictionary> ();
             dynamic row = new DynamicDictionary ();
             row.customer = "Customer1";
             row.Period = "2008";
             row.Item = "Item1";
             row.Cost = "20";
             rows.Add (row);
            xamGrid.ItemsSource = rows


Can I use DynamicDictionary as ItemsSource???
Thank you for your reply.