2012-01-04 58 views
0

新年快乐!感谢您阅读本文!Tabcontrol contentTemplate定位

我有定位为的ContentTemplate动态内容的问题,我有以下几点:

<TabControl ItemsSource="{Binding Cats}"> 
      <TabControl.ItemTemplate> 
       <DataTemplate> 
        <TextBlock Text="{Binding Name}" FontSize="16" FontWeight="Bold"></TextBlock> 
       </DataTemplate>     
      </TabControl.ItemTemplate> 
      <TabControl.ContentTemplate> 
       <DataTemplate> 
        <WrapPanel> 
         <ItemsControl ItemsSource="{Binding Products}"> 
          <ItemsControl.ItemTemplate> 
           <DataTemplate> 
            <Button Content="{Binding Name}" Height="25" Width="100"></Button> 
           </DataTemplate> 
          </ItemsControl.ItemTemplate> 
         </ItemsControl> 
        </WrapPanel> 
       </DataTemplate> 
      </TabControl.ContentTemplate> 
     </TabControl> 

的的ItemsSource绑定猫返回分类 的列表,并在每个类别有返回列表的属性产品

enter image description here

目前显示的是垂直堆叠的所有按钮,但我需要的按钮,以填补wrapPanel。什么我找的ContentTemplate一个例证:

enter image description here

任何想法,将不胜感激!

回答

2

您需要使用WrapPanel作为ItemsPanel模板。请参阅this问题以供参考。基本上,你需要在添加此XAML:

<ItemsControl ItemsSource="{Binding Products}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Button Content="{Binding Name}" Height="25" Width="100"></Button> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

注意:你实际上并不需要设置WrapPanelOrientation财产,它只是在那里明确地着想。

+0

该死的应该已经实现了那里的包装.. 非常感谢您的帮助! – Sentinel 2012-01-04 14:26:58