问题
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.
来源:https://stackoverflow.com/questions/1736696/silverlight-3-dataform-how-to-add-fieds-at-runtime