【发布时间】:2012-03-26 11:51:15
【问题描述】:
这是我的列表框的外观:
<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} 中有一些选项
标签: windows-phone-7 listbox windows-phone-7.1 observablecollection