2011-05-24 30 views
1

我想創建一個有x colums和y行的表。 該表可以有一個項目源,並且此表中的每個單元格都將是一個項目。 例如,如何將圖像集合綁定到表格,其中每個圖像都是一個項目。 如果有人能與liskbox所以更好listbox綁定到集合,與表格佈局其中每個單元格是集合的項目

實現這個這是我的代碼:

<ListBox Grid.Row="2"> 
    <ItemsControl ItemsSource="{Binding Projects, Mode=TwoWay}"> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <toolkit:WrapPanel /> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Image Source="{Binding Path=ProjectIcon, Mode=TwoWay}" Height="30" Width="30" /> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 
</ListBox> 

回答

0

你正在尋找的控制是從Silverlight的ToolkitWrapPanel

<ItemsControl ItemsSource="{Binding ImageSet}"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <toolkit:WrapPanel /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Image Source="{Binding}" /> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

謝謝you.when你寫的項目控制你的意思是我可以寫,而不是它的一個列表框例如?以及如何我可以指定在這個控制中,我想每行4項? – pavel 2011-05-24 14:03:22

+0

@Pavel:將ItemsControl的寬度設置爲單個項目寬度的4倍。但是,你是否有充分的理由將自己限制在4? – AnthonyWJones 2011-05-24 14:38:39

+0

它也寫我沒有找到類型「WrapPanel」,因爲http://schemas.microsoft.com/winfix/2006/xaml/presentation/toolkit是一個未知的命名空間。有什麼不對? – pavel 2011-05-24 15:00:19

相關問題