Question

I have a styled ContentControl with a DependencyProperty which, among others, has a DataTemplate property (StatusTemplate) that I have to assign to a DataTemplate I got in resources (StatusTemplate1).

The ContentControl is shown and the 'Binding:: ' text from StatusTemplate1 is also displayed, but the binding is empty. If I'm not mistaken, ContentControl doesn't propagate its DataContext to their Content, so the question is: is there any workaround I could use in order StatusTemplate1 receives the DataContext ? I'd prefer to use XAML only for this, but I've got no problem if code-behind is the way to go.

EDIT: the problem here is how to propagate the DataContext to the dependency property StatusTemplate. I changed the question title as it seems to be misleading.

The DataTemplate:

<DataTemplate x:Key="StatusTemplate1">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Binding:: " />
        <TextBlock Text="{Binding}" />
    </StackPanel>
</DataTemplate>

And the ContentControl:

<ContentControl Style="{Binding Path=Status, Converter={StaticResource StatusToStyleConverter}}" 
    dp1:AddOn.StatusTemplate="{StaticResource StatusTemplate1}">
</ContentControl>

Thanks

Was it helpful?

Solution

I have a very similar scenario, and if I recall correctly,

Content="{Binding}"

As an attribute of the contentcontrol actually works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top