Silverlight 3 Dataform - how to add fieds at runti

2019-06-13 17:17发布

问题:

I am creating a DataForm from dynamic data (so I can't create the columns in the xaml), I currently create columns for my DataGrid (I have not worked out how I can create a button + event in a colomn yet)

foreach (var item in headings.Entities)
                    {
                        theDataGrid.Columns.Add(
                            new DataGridTextColumn
                            {
                                Header = item.Label,
                                Binding = new Binding(item.LocalName)
                            });
                    }

I cannot see any methods to add fields to a DataForm at runtime, however...

回答1:

You'd be better off not creating your datagrid columns in code, but using bindings instead. Just bind the datagrid to the headings.Entities collection.

The same thing with your DataForm, just bind your item to it and it should create all the proper fields for you.