Posted 14 years ago
by Phil Devaney
-
Senior Software Engineer,
Serck Controls Ltd
Version: 11.1.0545
Platform: .NET 4.0
Environment: Windows 7 (32-bit)

I've been trying to set bindings on properties on PartEditBoxes used in data grid columns. Normally, the way to do this is to use the EditingElementStyle property, but because of the way DataGridBoundColumnBase.ApplyStandardValues works this doesn't work. The problem is that all the values from the DataGridPartEditBoxColumn are passed through to the PartEditBox, so these local values override any binding set in the EditingElementStyle.
To work around this, I made the following change to DataGridBoundColumnBase.ApplyValue and built my own version of Editors.Interop.DataGrid:This does two things:
- If there is no local value set on the column, the property is not set on the edit box so it will pick up any style value. This may have an adverse effect if a property has different defaults for the column and the edit box.
- If there is a binding set on the column, it sets the same binding on the edit box. This seems to work OK in the cases I tried, but there may be subtle problems related to the DataContext.
Can you think of a better way of doing this? If not, should this fix be added to the project on CodePlex?
Phil
To work around this, I made the following change to DataGridBoundColumnBase.ApplyValue and built my own version of Editors.Interop.DataGrid:
protected virtual void ApplyValue(DependencyProperty sourceProperty, FrameworkElement targetElement, DependencyProperty targetProperty)
{
var sourceValue = this.ReadLocalValue( sourceProperty );
if ( sourceValue != DependencyProperty.UnsetValue )
{
var expr = sourceValue as BindingExpression;
if ( expr != null )
BindingOperations.SetBinding( targetElement, targetProperty, expr.ParentBinding );
else
targetElement.SetValue( targetProperty, this.GetValue( sourceProperty ) );
}
}
- If there is no local value set on the column, the property is not set on the edit box so it will pick up any style value. This may have an adverse effect if a property has different defaults for the column and the edit box.
- If there is a binding set on the column, it sets the same binding on the edit box. This seems to work OK in the cases I tried, but there may be subtle problems related to the DataContext.
Can you think of a better way of doing this? If not, should this fix be added to the project on CodePlex?
Phil