Windows phone 7 WP7列表框滚动不工作

Windows phone 7 WP7列表框滚动不工作,windows-phone-7,listbox,scroll,Windows Phone 7,Listbox,Scroll,我在WP7用户控件中有以下XAML标记。我的问题是,当我的列表框中包含的项目超过页面所能容纳的数量时,它将无法正常滚动。我可以用手指向上平移来滚动列表,但一旦我移开手指,它就会跳回列表顶部(如果列表很长,那么滚动甚至无法达到这个有限的范围) 我尝试过许多不同的布局,但都没有成功,例如,在ScrollViewer中包装ListBox,使用StackPanel代替网格,移除包装面板并用网格替换 其他类似的问题建议删除StackPanel(我这样做了,但没有什么区别)或使用ScrollViewer(不

我在WP7用户控件中有以下XAML标记。我的问题是,当我的列表框中包含的项目超过页面所能容纳的数量时,它将无法正常滚动。我可以用手指向上平移来滚动列表,但一旦我移开手指,它就会跳回列表顶部(如果列表很长,那么滚动甚至无法达到这个有限的范围)

我尝试过许多不同的布局,但都没有成功,例如,在ScrollViewer中包装ListBox,使用StackPanel代替网格,移除包装面板并用网格替换

其他类似的问题建议删除StackPanel(我这样做了,但没有什么区别)或使用ScrollViewer(不起作用)

承载UserControl的页面使用了一个GestureListener——我删除了它,但仍然没有任何区别

<Grid x:Name="LayoutRoot"
      Background="SteelBlue">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <!--<TextBlock Grid.Row="0"
               Text="Search"
               Style="{StaticResource PhoneTextTitle2Style}" />-->

    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Text="Search Type"
                   Grid.Column="0"
                   VerticalAlignment="Center" />

        <RadioButton Content="RMB/RSD"
                     Grid.Column="1"
                     IsChecked="{Binding Path=SearchType, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RMB, Mode=TwoWay}" />

        <RadioButton Content="Name"
                     Grid.Column="2"
                     IsChecked="{Binding Path=SearchType, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Name, Mode=TwoWay}" />
    </Grid>

    <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Text="Search Term"
                   Grid.Column="0"
                   VerticalAlignment="Center" />

        <TextBox Grid.Column="1"
                 Text="{Binding SearchTerm, Mode=TwoWay}"
                 InputScope="{Binding SearchTermInputScope}">
            <i:Interaction.Behaviors>
                <b:SelectAllOnFocusBehavior />
            </i:Interaction.Behaviors>
        </TextBox>

    </Grid>

    <Button Grid.Row="2"
            Content="Find"
            cmd:ButtonBaseExtensions.Command="{Binding FindDeliveryPointsCommand}" />

    <ListBox Grid.Row="3"
             ItemsSource="{Binding SearchResults}"
             ScrollViewer.VerticalScrollBarVisibility="Auto">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <toolkit:WrapPanel Orientation="Horizontal"
                                   Width="480"
                                   Background="{Binding RMB, Converter={StaticResource alternateColorConverter}}">
                    <TextBlock Text="{Binding RMB}"
                               FontSize="26"
                               Foreground="Navy"
                               Padding="5"
                               Width="60" />
                    <TextBlock Text="{Binding HouseholdName}"
                               FontSize="26"
                               Foreground="Navy"
                               Padding="5"
                               Width="420" />
                    <TextBlock Text="{Binding StreetWithRRN}"
                               FontSize="26"
                               Foreground="Navy"
                               Padding="5" />
                    <TextBlock Text="{Binding Street.Locality.Name}"
                               FontSize="26"
                               Foreground="Navy"
                               Padding="5" />
                </toolkit:WrapPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

指定ListBox.Height-类似于Height=“200”。就像现在一样,ListBox会自动扩展以容纳所有加载的项目,并且它会从屏幕中显示出来。因此,您将获得没有滚动条的大页面


添加ListBox.Height时,ListBox区域不会增长。相反,ListBox ScrollViewer将被激活,您将获得所需的效果。

当ListBox的高度根据页面上的其他控件发生变化时,我使用数据绑定

<StackPanel x:Name="ContentPanel" Grid.Row="1">            
        <ListBox x:Name="LstSample" Height="{Binding ElementName=ContentPanel, Path=ActualHeight}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding ImagePath}" Stretch="None"/>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Name}" FontSize="45"/>
                            <TextBlock Text="{Binding Group}" FontSize="25"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>


你的问题有点太复杂了。我建议创建一个新页面,其中包含一个充满字符串的列表框,并验证该页面是否正确滚动。然后慢慢地添加上面的代码。当它停止工作时,你已经找到了你的原因!注意ScrollViewer.VerticalScrollBarVisibility是不需要的。谢谢-您的解决方案工作得很好。我想这很明显-但我错过了它。但如果列表动态变化,并且无法设置高度,该怎么办?在这里,我选择在windows phone emulator的所有屏幕中显示height=“550”。旧线程,但刚才被困在这个屏幕上。我发现这个解决方案是有效的,即使是嵌套的绑定列表,除非由于某种原因,高度超过了屏幕高度。如果列表框最终比屏幕长,这无关紧要——将高度设置为eg Height=“550”将起作用。