Silverlight 3 - HeaderedItemsControl ControlTemplate

Posted by user208662 on Stack Overflow See other posts from Stack Overflow or by user208662
Published on 2010-04-19T13:00:43Z Indexed on 2010/04/19 13:03 UTC
Read the original article Hit count: 485

Filed under:

Hello,

I am trying to create a HeaderedItemsControl where the headers are frozen. In an attempt to accomplish this, I have been trying to build on the default control template generated by Blend. I am using this default template in the following manner:

<controls:HeaderedItemsControl x:Name="informationItemsControl">
  <controls:HeaderedItemsControl.Template>
    <ControlTemplate>
      <Grid x:Name="Root">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <ContentControl x:Name="HeaderContent" Content="{TemplateBinding Header}" 
          ContentTemplate="{TemplateBinding HeaderTemplate}"/>
    <ItemsPresenter x:Name="Items" Grid.Row="1"/>
      </Grid>
    </ControlTemplate>
  </controls:HeaderedItemsControl.Template>

  ...
</controls:HeaderedItemsControl>

Oddly, when I use the default template, a blank screen appears in my application. A JavaScript error bubbles up that says:

Error: Unhandled Error in Silverlight Application 
Code: 2012    
Category: ParserError       
Message: Unknown attribute Content on element ContentControl.     
File:      
Line: 6     
Position: 107     

Source File: http://localhost:2995/
Line: 60

I noticed that this error appears as long as either Content="{TemplateBinding Header}" or ContentTemplate="{TemplateBinding HeaderTemplate}" exist in the ControlTemplate. If I remove both of those, the items appear just fine (but no header). I tried with a simple header that was just a TextBlock and I still received the error. What am I doing wrong? How do I get the Header to display within the ControlTemplate?

© Stack Overflow or respective owner

Related posts about Silverlight