I hope this isn't a duplicate but I can't find any documentation or examples on how to actually use ScrollToVerticalOffset()
. I'm using it in a Windows Phone 8 app, but I think it will still apply to WP7 and Silverlight (although, feel free to correct me if I'm wrong).
So here is my basic set up (pseudo-code from memory):
<phone.PivotItem>
<ScrollViewer>
<Grid Height="1500">
<Grid.RowDefinitions>
<!-- about 20 rows, all auto-height -->
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBox x:Name="txt1" />
</Border>
<Border Grid.Row="1">
<TextBox x:Name="txt2" />
</Border>
<!-- ...... -->
<Border Grid.Row="19">
<TextBox x:Name="txt20" />
</Border>
</Grid>
</ScrollViewer>
</phone.PivotItem>
So as you can see, I've got a ScrollViewer
within a PivotItem
, and inside is a Grid
. In the Grid
there are about 20 TextBox
s, each within a Border
. I am dynamically setting focus to one of these TextBox
s when this page loads, so anytime I set focus to TextBox
#6-20 (roughly) - I have to manually scroll down to see it. I want to auto-scroll my ScrollViewer
so that whichever TextBox
has focus, it will be centered for the user to see.
The documentation for ScrollToVerticalOffset()
says:
Scrolls the content that is within the ScrollViewer to the specified vertical offset position.
And that it accepts a type of System.Double
.
What I don't understand is A) the value I'm supposed to pass, and B) how I could even get that value? Is it supposed to be a number between 0 and the height of my Grid
(1500)? If so, how could I determine the position of any given TextBox
so I can scroll to it?
If there are any straightforward examples, please feel free to link out to them. I'm not sure if the content within the ScrollViewer
matters when calling this method, but in case it does I wanted to show exactly how I'm using it.
Many thanks in advance!
LongListSelector
, and I haven't done enough research to know if it would be a better option or not. Basically, I'm making a "top ten leaderboard" type thing which will display the top ten names & scores. If a new score is > than the 10th score, I'll insert aTextBox
into the correct position and let the user save it. My pseudo-code above obviously doesn't reflect all of this functionality though. – NannanaTextBlocks
that I'm using as labels, and then they get adjusted/shifted for the "new entry" and aTextBox
is put in it's place to let the user save their name into that position. – Nannana