listbox scroll jumps to start
I'm using a list box, and each item is a user control.
I'm able to scroll in the emulator and see the all the items. but if I leave the mouse button the list jumps to the start. Is that how the emulator behavives? or I have a bug? I tried using the scroll viewer but it did not help.
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
<ListBox Name="actionsListBox" VerticalAlignment="Top" ItemsSource="{Binding Path=Actions}" BorderThickness="1">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<commonWPControls:MetadataView DataContext="{Binding}" ButtonClick="MetadataView_ButtonClick" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
and the user control looks like this:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button DataContext="{Binding}" Grid.Column="0" Width="100" Height="100" Click="Button_Click" BorderThickness="0">
<Button.Background>
<SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
</Button.Background>
<Image x:Name="pictureImage" Source="{Binding Path=Picture}" />
</Button>
<StackPanel VerticalAlignment="Center" Grid.Column="1" >
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextTitle2Style}" Vert开发者_如何学PythonicalAlignment="Top" />
<TextBlock Text="{Binding Description}" VerticalAlignment="Top" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
</Grid>
There are a number of issues with using a usercontrol inside a ListBox. These include performance and issues with item virtualization which cna mean that items aren't shown or are shown more than once. For this reason the use of usercontrols inside a listbox is not recommended.
The issue you are seeing is probably related to determining the height of the actual listbox or the height of height of each item.
If you move the contents of the user control directly into thte item template does this still happen? If it does then it woudl indicate a problem with the complexity of each item affecting the determinatino of the item height.
If you just have a very simple itemtemplate (i.e. just a textblock) does this still happen? If so, it would indicate an issue with determining the availabel height of the listbox. Try setting the height of the listbox explicitly to resolve this.
You also have a very complex visual tree with lots of nested grids. Try removing some of these.
精彩评论