2010-08-25 63 views

回答

25

使用ItemsPanel性質與水平的StackPanel更換面板:

<ListBox> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal"/> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
</ListBox> 

如果你想這樣做的風格,只需添加一個setter用於設置ItemsPanel屬性:

<Style TargetType="ListBox"> 
    <!-- Rest of the style --> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal"/> 
      </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

tx Quartermeister的答案,但我想從風格默認情況下做到這一點。我將再次編輯樣式 – Malcolm 2010-08-25 12:09:06

+0

hey Quartermeister tx,但在樣式完成後會拋出一個錯誤: 消息:在使用ItemsSource之前,Silverlight Application Items集合中的未處理錯誤必須爲空。在System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable值) – Malcolm 2010-08-25 12:23:02

+0

@Malcom:它很難看到這可能會打破它。如果您完全保留ItemsPanelTemplate屬性,將其作爲默認的垂直堆棧面板,那麼您是否仍然收到錯誤? – AnthonyWJones 2010-08-25 12:29:26