這是怎麼看我的列表框:WP7 - 顯示在列表框中的一些項目按鈕,點擊後顯示更多的內容
<ListBox x:Name="ForthListBox"
Margin="0,0,-12,0"
ItemsSource="{Binding Tops}"
Tap="ForthListBox_Tap" Style="{StaticResource TopListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<TextBlock Text="{Binding Title}"
TextWrapping="Wrap"
Margin="12,0,0,0"
FontSize="40"/>
<TextBlock Text="{Binding Rating}"
TextWrapping="NoWrap"
Margin="12,-6,0,0"
Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我編輯的列表框模板,所以我在最後有按鈕:
<Style x:Key="TopListBoxStyle" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
<StackPanel><ItemsPresenter/>
<Button x:Name="BtnLoadMore" Click="BtnLoadMore_Click" Content="Další" />
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
並且我在MainViewModel
中有ObservableCollection<Top>()
,我將它綁定到DataContext
。沒關係,它顯示我的項目,但我怎樣才能設置,我想在該列表框中顯示50個項目,並且當我點擊按鈕後,我想從集合中再次顯示前50個項目和50個項目,並且一次又一次地在收藏中沒有更多項目沒有顯示,然後隱藏按鈕。謝謝
我想,我會收集2本。一個用於綁定,我只是添加我想要顯示的項目,第二個將有所有項目,當我點擊按鈕時從中獲得項目,但我認爲這個解決方案不是最好的。我希望{Binding}中有一些選項 – 2012-03-26 14:00:52