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?
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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.