views:

274

answers:

2

I have specified a userControl as a dataTemplate.

<TabControl IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=Pages}">
   <TabControl.ContentTemplate>
      <DataTemplate>
         <uc:ItemTemplateControl />
      </DataTemplate>
   </TabControl.ContentTemplate>
</TabControl>

The userControl is very easy and just binds to a string property, which works fine. But the strange thing is, there's only a single instance created of the userControl (debugger in ctor hits only one time), even though I have multiple items...

How can I create separate userControl instances for each item?

A: 

Try putting your user control inside repeater control and bind the repeater control with your data source. For example,

<asp:Repeater ID="repeatInfo" runat="Server">
 <ItemTemplate>
  <tr>
     <td>
        <Your control/>
     </td>
  </tr>
 </ItemTemplate>
</asp:Repeater>
Sachin Gaur
we're talking about wpf here, not asp. And the binding itself already works...
Jo-wen
A: 

It doesn't work when you specify the dataTemplate directly in the tabControl. You must specify the dateTemplate as a separate resource.

Jo-wen