Exemplo n.º 1
0
        private IEnumerable <string> PropertyNames; //Store the properties names of the dynamic object

        public MainWindow()
        {
            InitializeComponent();

            PropertyNames = new List <string>();

            for (int i = 0; i < 5; i++)
            {
                dynamic item = new DynamicObjectClass();
                item.A = "Property A value - " + i.ToString();
                item.B = "Property B value - " + i.ToString();

                PropertyNames = item.GetDynamicMemberNames();
                items.Add(item);
            }

            //Add Columns
            dataGrid.Columns.Add(new DataGridTextColumn()
            {
                Header = "A", Binding = new Binding("A")
            });
            dataGrid.Columns.Add(new DataGridTextColumn()
            {
                Header = "B", Binding = new Binding("B")
            });
            dataGrid.ItemsSource = items;
        }
Exemplo n.º 2
0
        private void AddRow_Click(object sender, RoutedEventArgs e)
        {
            dynamic item = new DynamicObjectClass();

            foreach (string PropertyName in PropertyNames)
            {
                item.TrySetMember(new SetPropertyBinder(PropertyName), "New Item - " + PropertyName);
            }
            items.Add(item);
        }