/// <summary> /// Fills this collection from a DataGrid. Creates one item for each Column, then one for each property. /// </summary> public PropertyColumnDataModelCollection(PropertyColumnEditor propertyColumnEditor, ModelItem dataGrid) { PropertyColumnEditor = propertyColumnEditor; _dataGrid = dataGrid; _initializing = true; try { object dataSource = _dataGrid.Properties[PlatformTypes.DataGrid.ItemsSourceProperty].ComputedValue; if (dataSource != null) { // Create a PropertyColumnDataModel for each column in the DataGrid's Columns Collection foreach (ModelItem dataGridColumn in _dataGrid.Properties[PlatformTypes.DataGrid.ColumnsProperty].Collection) { PropertyColumnDataModel columnModel = new PropertyColumnDataModel(this); columnModel.SetInitialColumn(dataGridColumn); this.Add(columnModel); } // Look through the column info the DataSource's properties and see if any match existing columns foreach (ColumnInfo columnGenerationInfo in DataGridDesignHelper.GetColumnGenerationInfos(dataSource)) { bool found = false; // only create a new item if we dont already have an item that matches based on the column binding. foreach (PropertyColumnDataModel columnModel in this) { if (columnModel.ColumnGenerationInfo == null && columnModel.BindingPath == columnGenerationInfo.PropertyInfo.Name) { // if we already have a column bound to this property, then must associate the property descriptor with it. columnModel.ColumnGenerationInfo = columnGenerationInfo; found = true; break; } } // if we dont have a column that binds to this property, add a new data object to represent this potential column if (!found) { this.Add(new PropertyColumnDataModel(this) { ColumnGenerationInfo = columnGenerationInfo }); } } } } finally { _initializing = false; } }
/// <summary> /// Opens the Edit Property-Bound Columns dialog for the given DataGrid /// </summary> public static void EditPropertyBoundColumns(ModelItem dataGridModelItem, EditingContext editingContext) { using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.ColumnsChanged)) { PropertyColumnEditor ui = new PropertyColumnEditor(editingContext, dataGridModelItem); // Use Windows Forms to show the design time because Windows Forms knows about the VS message pump System.Windows.Forms.DialogResult result = DesignerDialog.ShowDesignerDialog(Properties.Resources.Edit_Property_Bound_Columns_Dialog_Title, ui); if (result == System.Windows.Forms.DialogResult.OK) { scope.Complete(); } else { scope.Revert(); } } }
/// <summary> /// Opens the Edit Property-Bound Columns dialog for the given DataGrid /// </summary> public static void EditPropertyBoundColumns(ModelItem dataGridModelItem, EditingContext editingContext) { using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.ColumnsChanged)) { PropertyColumnEditor ui = new PropertyColumnEditor(editingContext, dataGridModelItem); // Use Windows Forms to show the design time because Windows Forms knows about the VS message pump System.Windows.Forms.DialogResult result = DesignerDialog.ShowDesignerDialog(Properties.Resources.Edit_Property_Bound_Columns_Dialog_Title, ui); if (result == System.Windows.Forms.DialogResult.OK) { scope.Complete(); } else { scope.Revert(); } } }