Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding from within a DataTemplate?
    text
    copied!<p>I'm building a Silverlight control and I'm trying to set up bindings for the Header and Body ContentControls through their respective DataTemplates. I'm not sure why, but this does not work (silently fails). My only guess is that it is because the DataTemplates are StaticResources. Can anyone offer advice? The control has the following default template:</p> <pre><code>&lt;Style TargetType="local:LayoutItem"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="local:LayoutItem"&gt; &lt;StackPanel&gt; &lt;StackPanel.Resources&gt; &lt;DataTemplate x:Key="DefaultHeaderTemplate"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding HeaderText}" FontSize="15"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="DefaultBodyTemplate"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding BodyText}" FontSize="12"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/StackPanel.Resources&gt; &lt;ContentControl x:Name="Header" ContentTemplate="{StaticResource DefaultHeaderTemplate}" /&gt; &lt;ContentControl x:Name="Body" ContentTemplate="{StaticResource DefaultBodyTemplate}" /&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; </code></pre> <p> </p> <p>Thanks!</p> <hr> <p>Update</p> <p>Actually, the following code does not work either, so my assumption about the StaticResources might be wrong.</p> <pre><code>&lt;ContentControl x:Name="Header"&gt; &lt;ContentControl.ContentTemplate&gt; &lt;DataTemplate x:Key="DefaultHeaderTemplate"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding HeaderText}" FontSize="15" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ContentControl.ContentTemplate&gt; &lt;/ContentControl&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload