我在WP7 UserControl中有以下XAML标记.我的问题是,当我的ListBox有更多的项目比适合在一个页面,它将不会滚动正确.我可以用手指向上滚动列表,但是一旦我删除我的手指,它就会跳回到列表的顶部(如果列表很长,那么滚动甚至不会在这个有限的范围内工作).
原文链接:https://www.f2er.com/windows/371653.html我尝试了许多不同的布局,没有成功,例如在ScrollViewer中包装ListBox,使用StackPanel而不是Grid,删除WrapPanel并将其替换为网格.
其他类似的问题建议删除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,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>