ScrollViewer.ChangeView returns false
Asked Answered
T

2

6

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);
Twitter answered 24/9, 2013 at 2:36 Comment(2)
Same here. For now I'm using ScrollToVerticalOffset, even though it's deprecated.Delete
I have the same problem with ScrottToHorizontalOffset. Changing to ChangeView(0,null,null) as the compiler warnings advise breaks it--no scrolling happens.Yeanling
H
1

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 ...

Homograph answered 12/3, 2015 at 12:21 Comment(0)
G
0

I believe this could be a factor of some of your property settings. Try stripping your ScrollViewer to it's minimum and also change your offset. You are telling it to scroll to 400 when your height is 400 so it could be a factor of it not being able to scroll to where you want (try setting it to (null, 200, null, null) to see if that works.

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

bool result = this.MainFeatureScrollViewer.ChangeView(null, 200, null, true);
Guilty answered 30/1, 2014 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.