本帖最后由 优客木子 于 2017-11-6 16:08 编辑
按如下代码设置绑定绑定: var column = new C1.WPF.DataGrid.DataGridTemplateColumn()
{
Header = item.ColumnName,
};
DataTemplate temp = new DataTemplate();
Binding bd = new Binding(item.ColumnName);
bd.Mode = BindingMode.TwoWay;
//生成Grid
FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid));
grid.Name = item.ColumnName;
//生成Button
FrameworkElementFactory button = new FrameworkElementFactory(typeof(CheckBox));
button.SetBinding(CheckBox.IsCheckedProperty, bd);
button.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(CheckBox_Click));
grid.AppendChild(button);
temp.VisualTree = grid;
column.CellTemplate = temp;
c1DataGrid1.Columns.Add(column);
给c1DataGrid1 设置ItemsSource 为DataTable的时候,会出现如下异常:FrameworkElementFactory 必须位于此操作的密封模板中。
|
|