2012-01-10 53 views
-2

我需要浮動列表框中的項目,使它們看起來像兩個線...我怎麼能?我試過,但他們不斷地出現一個又一個...我的xml:在列表框中浮動的項目

<ListBox Name="listacomico" Width="480" Margin="0,112,0,0"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Button Background="White" BorderBrush="#346699" Click="apri_comico" Name="{Binding Myordine}" Margin="0,0,0,0" Padding="0" HorizontalAlignment="Left" HorizontalContentAlignment="Left"> 
        <Button.Content> 
         <StackPanel Orientation="Horizontal" Width="125"> 
          <Image Source="{Binding Myimmagine}" HorizontalAlignment="Left" VerticalAlignment="Top" /> 
         </StackPanel> 
        </Button.Content> 
       </Button> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
+0

你根本沒有任何意義。 – 2012-01-10 12:28:37

+0

有人可以幫助我嗎?是可以做出每行兩個項目? – Zak 2012-01-10 14:13:12

+0

爲了清晰起見,你能編輯這個問題嗎?我嘗試過多次閱讀,仍然無法弄清楚你在問什麼。 – 2012-01-10 14:17:02

回答

2

如果你想顯示的項目彼此相鄰,你將不得不使用一個WrapPanel,因爲它已經在被提出上面的評論。

這不是與ItemTemplate相關的行爲。 ItemTemplate將定義項目的外觀。

達到你想要做什麼,你必須定義ItemsPanel這樣的:

<ListBox ItemsSource="{Binding CollectionSource}"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <toolkit:WrapPanel /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox> 

工具包:意味着我有一個名爲工具包的命名空間,我的XAML的頂部:

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 

如果您的項目尚未完成,您必須添加對Silverlight Toolkit for WP7的引用!

+0

非常感謝!有用! 我已經使用了工具包,因爲我使用了過渡效果。 現在,我在這裏...我可以問你一些事情嗎?我需要通過xaml.cs來替換圖像的來源,我在xaml中有這個:,並在.cs:faccia.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(」/ Myapp; component/comici /「+ url_img.Value));但它不顯示任何東西! – Zak 2012-01-11 12:43:14

+0

你確定Uri是正確的嗎?您可以在ImageFailed事件上添加事件處理程序,以確保: 但是,是否有充分的理由從代碼隱藏加載圖像?你不能使用綁定? – 2012-01-11 19:34:50