Answered by:
scrollviewer scrolling automatically in window 8

Question
-
<
GridGrid.Row="1">
<ScrollViewerName="myScrollViewer"Width="400"VerticalScrollBarVisibility="Hidden"HorizontalScrollBarVisibility="Auto">
<ImageName="MainImage"Source="/Assets/enterword-black-board.png"Stretch="None" />
</ScrollViewer>
</Grid>
protected
overridevoidLoadState(ObjectnavigationParameter, Dictionary<String, Object> pageState)
{
myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset + (40));
}
I have large size image inside a scrollviewer. I want when the page loaded scroll viewer move to end automatically so I can see the whole image when scrollviewer move. if this possible through storyboard animation then it is more better. please help.
Tuesday, November 26, 2013 8:15 PM
Answers
-
I think you need put the code in the ScrollViewer loaded event instead of the page loaded.
<ScrollViewer x:Name="myScrollViewer" Height="219" VerticalAlignment="Top" Width="314" Loaded="srcloaded" HorizontalScrollBarVisibility="Visible"> <Image Source="Assets/1.png" Height="564" Width="538"></Image> </ScrollViewer>
And the code behind:
private void srcloaded(object sender, RoutedEventArgs e) { myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset + (40)); }
For the animation stuff, in win8 you can try this extension: http://winrtxamltoolkit.codeplex.com/
ScrollViewerExtensions.ScrollToHorizontalOffsetWithAnimation(), .ScrollToVerticalOffsetWithAnimation() - provide a way to scroll a ScrollViewer to specified offset with an animation.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by vinittyagi Wednesday, November 27, 2013 7:54 AM
- Unmarked as answer by vinittyagi Wednesday, November 27, 2013 7:57 AM
- Marked as answer by vinittyagi Wednesday, November 27, 2013 7:59 AM
Wednesday, November 27, 2013 6:07 AMModerator
All replies
-
Hi vinittyagi,
ScrollToHorizontalOffset is a correct method and you could use it by win8 apps, for win8.1 a better one is for you: ChangeView methods, by this you could decide if you wan to enable the animation or not.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Wednesday, November 27, 2013 1:21 AMModerator -
I am working on window 8 . my problem is my scroll viewer is not moving when the page load
Wednesday, November 27, 2013 4:27 AM -
I think you need put the code in the ScrollViewer loaded event instead of the page loaded.
<ScrollViewer x:Name="myScrollViewer" Height="219" VerticalAlignment="Top" Width="314" Loaded="srcloaded" HorizontalScrollBarVisibility="Visible"> <Image Source="Assets/1.png" Height="564" Width="538"></Image> </ScrollViewer>
And the code behind:
private void srcloaded(object sender, RoutedEventArgs e) { myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset + (40)); }
For the animation stuff, in win8 you can try this extension: http://winrtxamltoolkit.codeplex.com/
ScrollViewerExtensions.ScrollToHorizontalOffsetWithAnimation(), .ScrollToVerticalOffsetWithAnimation() - provide a way to scroll a ScrollViewer to specified offset with an animation.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by vinittyagi Wednesday, November 27, 2013 7:54 AM
- Unmarked as answer by vinittyagi Wednesday, November 27, 2013 7:57 AM
- Marked as answer by vinittyagi Wednesday, November 27, 2013 7:59 AM
Wednesday, November 27, 2013 6:07 AMModerator -
Thanks james for your quik reply
Its working fine but if I does not set the image width and set property image stretch none then it not scrolled.
what is the reason ?
again thanks for your reply
Wednesday, November 27, 2013 8:01 AM -
Hi vinittyagi,
Yes, I can reproduce it, but currently I don't know why, I think the reason might be with ActualWidth and ActualHeight of the Image(not quite sure), I will try to figure it out and update you later or involve some senior engineers to look this for you.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.
- Edited by Jamles HezModerator Wednesday, December 4, 2013 2:00 AM
Thursday, November 28, 2013 8:17 AMModerator -
Hi vinittyagi,
If you output the timestamp for Scrollviewer loaded event and Image loaded event, you will find that Scrollviewer rendered earlier than the Image, Loaded means the control is ready for interaction, therefore when the Image is not loaded, the Scrollviewer cannot apply ScrollToHorizontalOffset() method. If you add a button to scroll the image after everything is really, that would works fine.
I believe that the issue is related with ActuallyHeight and ActuallyWidth, when we specify the Height or Width for Image, the system already know the size of the image before the image is loaded, and Scrollviewer can scroll correctly for a Item.
Hope it help you.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Thursday, December 12, 2013 3:19 AMModerator