Content Created Using a ContentTemplate Does Not Have a DataContext Dataset for Silverlight ContentControl

In my Silverlight 4 application, I have a ContentControl with the ContentTemplate property associated with the property in the data context. It works great. However, the contents of the template after displaying have a DataContext set to null . I would like the content to inherit the same DataContext as for the ContentControl . Is there any way to achieve this?

+6
data-binding silverlight datatemplate
source share
2 answers

I found an alternative way to accomplish what was required. In my case, the ContentControl template (not the content template) was inconsequential, so I turned the DataTemplate objects into ControlTemplate objects and attached the Template property to the ContentControl instead of the ContentTemplate . The data context was saved if I did it this way.

-one
source share

The ContentControl template has the ContentControl Content property as a DataContext. Therefore try

 <ContentControl Content="{Binding}" /> 

if it is just the current DataContext.

+8
source share

All Articles