How to bind textbox text property, within datatemplate, to ContentControl Content property?
(Without bindng via ElementName)
This is my code( that doesn’t work):
<Window.Resources>
<DataTemplate x:Key="Temp">
<TextBox TextWrapping="Wrap" Text="{TemplateBinding Content}" Height="20" Width="Auto"/>
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl ContentTemplate="{DynamicResource Temp}" Content="1"/>
</Grid>
Use a relative source binding:
Edit: I probably should note that, in terms of what the binding targets, this is equivalent to
{Binding}, as theDataContextin theContentTemplateis theContent.However binding directly to the
DataContextwill not propagate back to the sourceDataContext, hence theContentof theContentControlwould not change when when using this binding (or the two-way compliant variation{Binding .}, which changes absolutely nothing as far as I can tell).