2012-01-04 9 views
0

すべてにとって幸せな新年!これを読んでくれてありがとう!タブコントロールのコンテンツテンプレートの位置付け

私は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

ItemsPanelテンプレートとしてWrapPanelを使用する必要があります。参照のために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