protected virtual void SetTitleBarContentBinding(DataGridContext dataGridContext) { if (dataGridContext != null) { Xceed.Wpf.DataGrid.Views.ViewBase view = dataGridContext.DataGridControl.GetView(); if ((view is TableView) || (view is TableflowView)) { return; } Column headerColumn = dataGridContext.Columns.MainColumn as Column; if (headerColumn != null) { BindingBase displayMemberBinding = headerColumn.GetDisplayMemberBinding(); if (displayMemberBinding == null) { if (dataGridContext.ItemsSourceFieldDescriptors == null) { throw new InvalidOperationException("An attempt was made to create a DisplayMemberBinding before the DataGridContext has been initialized."); } string name = headerColumn.FieldName; ItemsSourceHelper.FieldDescriptor fieldDescriptor; dataGridContext.ItemsSourceFieldDescriptors.TryGetValue(name, out fieldDescriptor); displayMemberBinding = ItemsSourceHelper.CreateDefaultBinding(this.DataContext is DataRow, name, fieldDescriptor, headerColumn, true, typeof(object)); } if (displayMemberBinding == null) { Debug.Assert(false, "displayMemberBinding is null."); this.ClearValue(DataRow.TitleBarContentProperty); } else { this.SetBinding(DataRow.TitleBarContentProperty, displayMemberBinding); } } } }
protected internal virtual void SetupDisplayMemberBinding(DataGridContext dataGridContext) { // Bind the cell content. Column column = this.ParentColumn as Column; if (column != null) { BindingBase displayMemberBinding = null; object dataContext = this.ParentRow.DataContext; // If the dataContext is our ParentRow, we do not create any binding if (dataContext != this.ParentRow) { displayMemberBinding = column.GetDisplayMemberBinding(); if (displayMemberBinding == null) { if ((dataGridContext == null) || (dataGridContext.ItemsSourceFieldDescriptors == null)) { throw new InvalidOperationException("An attempt was made to create a DisplayMemberBinding before the DataGridContext has been initialized."); } if (!DesignerProperties.GetIsInDesignMode(this)) { bool isDataGridUnboundItemProperty; displayMemberBinding = ItemsSourceHelper.AutoCreateDisplayMemberBinding(column, dataGridContext, dataContext, out isDataGridUnboundItemProperty); column.IsBoundToDataGridUnboundItemProperty = isDataGridUnboundItemProperty; } column.IsBindingAutoCreated = true; column.SetDisplayMemberBinding(displayMemberBinding); } } if (displayMemberBinding != null) { m_canBeRecycled = DataCell.VerifyDisplayMemberBinding(displayMemberBinding); BindingOperations.SetBinding(this, Cell.ContentProperty, displayMemberBinding); XmlElement xmlElement = this.GetValue(Cell.ContentProperty) as XmlElement; if (xmlElement != null) { // Convert binding to an InnerXML binding in the case we are bound on a XmlElement // to be able to refresh the data in the XML. //under any circumstances, a cell that is bound to XML cannot be recycled m_canBeRecycled = false; BindingOperations.ClearBinding(this, Cell.ContentProperty); this.ClearValue(Cell.ContentProperty); Binding xmlElementBinding = new Binding("InnerXml"); xmlElementBinding.Source = xmlElement; xmlElementBinding.Mode = BindingMode.TwoWay; xmlElementBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit; BindingOperations.SetBinding(this, Cell.ContentProperty, xmlElementBinding); } } } }