/// <summary> /// /// </summary> /// <param name="headerText"></param> /// <returns>索引</returns> public void AddColumn(DesignerDataGridColumn column) { //添加列,获取坐标 ColumnDefinition cd = new ColumnDefinition(); HeaderGrid.ColumnDefinitions.Add(cd); int lastIndex = HeaderColumnsCount - 1; column.Position._columnIndex = lastIndex; //设置宽度 cd.SetBinding(ColumnDefinition.WidthProperty, new Binding("ColumnWidth") { Source = column }); BoardDataGridColumn bd = new BoardDataGridColumn(column); HeaderGrid.Children.Add(bd); bd.Uid = column.Name; //内容 ColumnDefinition cd2 = new ColumnDefinition(); cd2.SetBinding(ColumnDefinition.WidthProperty, new Binding("ColumnWidth") { Source = column }); ContentGrid.ColumnDefinitions.Add(cd2); }
public void RemoveColumn(DesignerDataGridColumn column) { //删除列 HeaderGrid.ColumnDefinitions.Remove(HeaderGrid.ColumnDefinitions[column.Position.ColumnIndex]); ContentGrid.ColumnDefinitions.Remove(ContentGrid.ColumnDefinitions[column.Position.ColumnIndex]); //删除元素 for (int i = 0; i < HeaderGrid.Children.Count; i++) { BoardDataGridColumn bd = HeaderGrid.Children[i] as BoardDataGridColumn; if (bd.Uid == column.Name) { HeaderGrid.Children.Remove(bd); break; } } ReorderColumns(column.Position.ColumnIndex); }