Binding to a DataGridTemplateColumn using the style used in the DataTemplate?

I have ComboBoxone that makes up DataTemplateand I am unable to bind its property IsEnabledto a property IsReadOnlyon the template DataGridTemplateColumn.

I got the following error in VS output window:

IsReadOnly property not found in '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}}" />
</Style>

I believe the problem is with how I point RelativeSourceto identify mine DataGridColumn. I tried:

  • RelativeSource={RelativeSource TemplatedParent}

  • RelativeSource AncestorType={x:Type DataGridColumn}

  • RelativeSource AncestorType={x:Type DataGridTemplateColumn}

I tried adding other stylists to this style, and they take effect, so I know that style and DataTemplateapply to controls.

PS

ComboBox DataTemplate DataGrid . , ( ). , .

+3
2

:

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

DataGridCell.IsReadOnly DataGridColumn.IsReadOnly.

+3

, , StaticResource . .

<DataGrid.Resources>
    <DataGridTemplateColumn x:Key="Column" .../>
</DataGrid.Resources>
<DataGrid.Columns>
    <StaticResource ResourceKey="Column"/>
</DataGrid.Columns>
{Binding IsReadOnly, Source={StaticResource Column}}

Binding.Source x:Reference , , . ​​ , , dependecy. StaticResource , , .

+1

All Articles