I am searching all the time for solution and cant get correct one.
I have grid that have width 960 and have ScrollViewer
in it. Now i would like to know value (horizontal offset) of my scroll while scrolling. All solutions that i am finding is for wpf/silverlight and it wont works for me.
Edit
Ok, here is the example code, xaml:
<ScrollViewer Name="Scroll" LayoutUpdated="ScrollViewer_LayoutUpdated" IsEnabled="True" Width="480" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<Grid x:Name="ContentPanel" Background="Red" Margin="12,0,12,0" Width="960">
<Rectangle Name="GreenRectangle" Fill="Green" Width="240" Height="240"></Rectangle>
</Grid>
</ScrollViewer>
c#
private void ScrollViewer_LayoutUpdated(object sender, EventArgs e)
{
GreenRectangle.Width = Scroll.HorizontalOffset;
GreenRectangle.Height = Scroll.HorizontalOffset;
}
But the problem is that it is not changing size all the time. Maybe my English is not well and you cant uderstand me. Here is movie example, i am sliding left right and the size is always the same. When i stop sliding it is changing size.
https://www.dropbox.com/s/eh28oavxpsy19bw/20130122_1601_56.avi
here's the XAML code I used
and here's the C# code behind
whenever the scroller is scrolled then the layout of the Grid (Container grid) changes so layout updated event is fired ... please try debugging by placing break point inside the event and look for the offset value ..
It is possible by using the scrollviewers dependency properties, it has a HorizontalOffset and a VerticalOffset. The trick is to bind event to the scrollviewer, but it can bee done in the load event handler. If you put a wide grid in your scrollviewer you can get the offset!
In your xaml file (MainPage sample here):
In your code behind file (MainPage.cs here):
Add the property ManipulationMode="Control" to your ScrollViewer. This is needed because otherwise the UI thread will not be notified with enough ScrollViewer scroll values to get a fluid animation – the normal mode is a performance optimization from Windows Phone that you need to bypass!