Wednesday, May 2, 2012

Binding to DataGridTemplateColumn using style applied within DataTemplate?

I have a ComboBox that composes a DataTemplate, and I'm having trouble binding its IsEnabled property to the IsReadOnly property on the templated DataGridTemplateColumn.

I've been receiving the following error in my VS output window:

'IsReadOnly' property not found on 'object' ''ContentPresenter'

ComboBox style:

<Style TargetType="{x:Type ComboBox}" x:Key="ProficiencyColumnComboBoxStyle">
<Setter Property="IsEnabled"
Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=IsReadOnly, Converter={StaticResource BooleanOppositeConverter}}" />

I believe the problem is with how I specify the RelativeSource intended to identify my DataGridColumn. I've tried:

  • RelativeSource={RelativeSource TemplatedParent}

  • RelativeSource AncestorType={x:Type DataGridColumn}

  • RelativeSource AncestorType={x:Type DataGridTemplateColumn}

I've tried adding other setters to this style, and they do take effect, so I know the style and DataTemplate are being applied to the controls.


I've used this same technique to bind another ComboBox within a DataTemplate to a property on the parent DataGrid of its templated columns. The difference is that here I'm using a converter, and trying to bind to a property on a column (instead of the grid.) However, even if I remove the converter from the above style, no binding takes place.

No comments:

Post a Comment