列表框不显示所有项目Windows phone 8.1



我试图在windows phone 8.1中使用绑定填充一个列表框。我无法看到控件中的所有项。

XAML:

<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock Text="Application Name" Style="{ThemeResource HeaderTextBlockStyle}" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>
    <StackPanel Grid.Row="1" x:Name="ContentRoot" Margin="19,0,19,0">
        <ComboBox 
            x:Name="ComboBox1"
            ItemsSource="{Binding}"
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Top" 
            SelectionChanged="ComboBox1_SelectionChanged"
            />
        <ListBox x:Name="ListBox1" ItemsSource="{Binding}" Height="1000">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" Margin="0">
                        <TextBlock Text="{Binding GameName}" Margin="2"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>
</Grid>

我在代码中填充列表框:

private ObservableCollection<Game> _Games = new ObservableCollection<Game>();
public StartPage()
{
    this.InitializeComponent();
    this.navigationHelper = new NavigationHelper(this);
    this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
    this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
    ListBox1.DataContext = _Games;
}
....
private async void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var group = _Groups[ComboBox1.SelectedIndex];
    games = await DataServer.GetGamesAsync(group.GroupName);
    _Games.Clear();
    foreach (var game in games.OrderBy(g => g.GameName))
    {
       _Games.Add(game);
    }
}

有69个游戏,但当我滚动列表时,我只能在模拟器的列表视图中看到大约28个。很明显,列表中还有更多的项目,但我无法滚动到它们。

StackPanel替换为Grid,并在您将添加的第二个网格中添加更多的RowDefinitionsStackPanels不动态调整自己的大小,因此不是调整屏幕大小,而是无限拉伸到底部。

最新更新