WPF won't let me set the binding on the binding path - is there any other way?

I have DataTemplateone that I use both CellTemplatefor GridViewColumn.

I want to write something like this for DataTemplate:

<DataTemplate
    x:Key="_myTemplate">
    <TextBlock
        Text="{Binding Path={Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewColumn}}, Path=Header}}" />
</DataTemplate>

My is GridViewbound to DataTable, and I want to bind to a column DataTablewhose name is equal to the header GridViewColumnto which it is bound DataTemplate. [Hope this made sense!]

Unfortunately this does not work. I get a XamlParseException: "A Binding" cannot be set in the "Path" property of type "Binding". Binding can only be set to the DependencyProperty of the DependenceyObject. "

How can I customize this?

Edit (add DanM comment to the question)

DataTemplate, DataContext DataTemplate. ?

+5
2

. Binding, .

Path Binding PropertyPath, Binding Path . , Path , .

Edit

, DataTemplate. XAML. .

, - ViewModel. XAML " " ViewModel.

0

?

{Binding Path=Header, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewColumn}}}
0

All Articles