In my Silverlight 4 application, I have a ContentControl
with its ContentTemplate
property bound to a property in the data context. That works fine. However, the content of the template once rendered has its DataContext
set to null
. I would like the content to inherit the same DataContext
as set for the ContentControl
. Is there a way to get this to happen?
Asked
Active
Viewed 2,190 times
6

Jacob
- 77,566
- 24
- 149
- 228
2 Answers
10
The ContentControl's template has the ContentControl's Content property as a DataContext. So try
<ContentControl Content="{Binding}" />
if this is merely the current DataContext.

John
- 6,693
- 3
- 51
- 90
-1
I found an alternate way to accomplish what was required. In my case, the template (not the content template) of the ContentControl
was unimportant, so I made my DataTemplate
objects into ControlTemplate
objects instead and bound the Template
property of the ContentControl
instead of ContentTemplate
. The data context was preserved if I did it this way.

Jacob
- 77,566
- 24
- 149
- 228
-
3+1 Question, -1 Answer; I came here wanting to know the same thing, but didn't find an answer. The accepted answer works around the question, but doesn't answer it. – tyriker Apr 27 '11 at 19:16