2011-06-16 39 views
2

對於這個例子,我有一個IList <>,它包含一系列也是列表的對象。例如,一個聯賽由一組球隊組成,這些球隊由球員組成。我想要的是具有一個滾動條的單個列表。如何在Windows Phone 7中獲得一系列IEnumerable對象看起來像一個大堆棧面板?

我試過嵌套列表框控件,但最終是多個滾動條的行爲可怕的堆棧。滾動很糟糕,它似乎隱藏了球隊球員名單的底部。

任何幫助將是偉大的!

回答

2

而不是ListBox,爲什麼不使用ItemsControl? A ListBox提供了選擇,如果你不需要這個,ItemsControlmore lightweight and will load faster。此外,通過ItemsControl,您可以完全控制託管項目的元素。這樣,您可以省略ScrollViewer

要渲染您的項目,請嘗試以下操作:

<ItemsControl ItemsSource={Binding League.Teams}> 
    <!-- use a StackPanel to host your elements --> 
    <ItemsControl.ItemsPanel> 
    <ItemsPanelTemplate> 
     <StackPanel Orientation="Vertical"/> 
    </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <!-- render each team --> 
    <ItemsControl.ItemTemplate> 
    <DataTemplate> 
     <!-- render each player within the team --> 
     <ItemsControl ItemsSource={Binding Players}> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
      <StackPanel Orientation="Vertical"/> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
      <!-- render the player's name --> 
      <TextBlock Text="{Binding Name}"/> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

我不知道爲什麼那麼是不是語法高亮,我的XAML :-( – ColinE 2011-06-16 07:59:26

0

您可以很容易地禁用ListBox的滾動條。只需將ScrollViewer.VerticalScrollBarVisibility="Disabled"添加到內部ListBox的XAML屬性即可。

相關問題