Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollViewer.ChangeView returns false

I have this ScrollViewer, which I add elements to programically:

<ScrollViewer VerticalSnapPointsAlignment="Near"
                          VerticalSnapPointsType="Mandatory"
                          VerticalScrollMode="Enabled"
                          VerticalScrollBarVisibility="Hidden"
                          ZoomMode="Disabled"
                          Width="400"
                          Height="400"
                          x:Name="MainFeatureScrollViewer"
                          ViewChanging="ScrollViewer_ViewChanging">
                <StackPanel x:Name="MainFeatureStackPanel" />
            </ScrollViewer>

When I call ChangeView like below it returns false and nothing happens. Why wouldn't this be working?

bool result = this.MainFeatureScrollViewer.ChangeView(null, 400, null, true);
like image 776
Steven Avatar asked Sep 24 '13 02:09

Steven


1 Answers

Just had the same problem - the base problem here was that my code did call ChangeView() twice in the same cycle - once on a non-GUI thread (which returned true, but of course did not really scroll to the desired position as it was not on the GUI thread), and later in a dispatcher method on the GUI thread (which returned false, because the scrollViewer apparently saw that it already had gotten a new scroll position which it was not showing yet).

Once I removed the ChangeView() calls that were not done on the GUI thread it worked fine. It would help if the documentation of ScrollViewer would explain in which cases it will return false, though ...

like image 116
TheEye Avatar answered Oct 01 '22 03:10

TheEye