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); } } } }