1

我已将 userControl 指定为 dataTemplate。

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

userControl 非常简单,只需绑定到一个字符串属性,效果很好。但奇怪的是,即使我有多个项目,也只创建了一个 userControl 实例(ctor 中的调试器只命中一次)...

如何为每个项目创建单独的 userControl 实例?

4

2 回答 2

0

当您直接在 tabControl 中指定 dataTemplate 时,它​​不起作用。您必须将 dateTemplate 指定为单独的资源。

于 2009-03-01T15:15:35.180 回答
-2

尝试将您的用户控件放在转发器控件中,并将转发器控件与您的数据源绑定。例如,

<asp:Repeater ID="repeatInfo" runat="Server">
 <ItemTemplate>
  <tr>
     <td>
        <Your control/>
     </td>
  </tr>
 </ItemTemplate>
</asp:Repeater>
于 2009-02-23T13:00:12.667 回答