ScrollViewer keeps snapping back to top

对着背影说爱祢 提交于 2019-12-11 19:29:25

问题


So I have this user control that contains a ListView, wrapped by a ScrollViewer. I set up my layout in the DataTemplate and it's displaying fine, but when you try to scroll down, it just snaps back to the top; it won't hold its position.

Here is the xaml:

                            <Border BorderThickness="1" BorderBrush="Black" Grid.Column="0" Grid.Row="0" 
                        Grid.RowSpan="2" Height="80" Width="80" VerticalAlignment="Top">
                                <Rectangle>
                                    <Rectangle.Fill>
                                        <ImageBrush Stretch="Fill" ImageSource="{Binding ImageUri}"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Border>

                            <TextBlock Grid.Column="1" Grid.Row="0" Style="{StaticResource DefaultText}" Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Left" />
                            <TextBlock Grid.Column="1" Grid.Row="1" Style="{StaticResource DefaultText}" Text="{Binding Description}" VerticalAlignment="Top" HorizontalAlignment="Left" />
                            <TextBlock Grid.Column="2" Grid.Row="0" Style="{StaticResource DefaultText}" Grid.RowSpan="2" Text="{Binding Cost}" Width="100" FontSize="40" HorizontalAlignment="Right" />

                        </Grid>
                    </Border>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ScrollViewer>

I saw another post suggesting that the problem is that the ScrollViewer is larger than the grid inside the item template. First of all, that sounds silly, so if I'm just using scrollviewer wrong, please just let me know how to fix that. Secondly, when I take the advice I saw in the article (set the height of the inner grid to be larger than the height of the scrollviewer), what happens is the height of every list item ends up being the height of the grid.

Any suggestions?

来源:https://stackoverflow.com/questions/31496568/scrollviewer-keeps-snapping-back-to-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!