开发者

ScrollViewer Content size change then ScrollToOffset not working

开发者 https://www.devze.com 2023-03-13 16:11 出处:网络
I am using a scrollviewer to display an Image within it. <ScrollViewer Name=\"scrollViewer1\" Height=\"500\" Width=\"500\" HorizontalScrollBarVisibility=\"Auto\" VerticalScrollBarVisibility=\"Auto

I am using a scrollviewer to display an Image within it.

<ScrollViewer Name="scrollViewer1" Height="500" Width="500" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" P开发者_如何学Cadding="0" >
    <Image x:Name="img1" Width="100" Source="/MyApp;component/Images/Test.jpg" />
</ScrollViewer>

But when I re-size the image in code, and immediately use the scrollViewer.ScrollToHorizontalOffset() (to reposition the image) it does not work :

img1.Width = 1000;
scrollViewer1.ScrollToHorizontalOffset(500);

I verified the ScrollableWidth property after the img1.Width = 1000 indeed it is not updated yet. So I used the UpdateLayout() right after I resize the image, great now the ScrollableWidth is updated :

img1.Width = 1000;
scrollViewer1.UpdateLayout();
scrollViewer1.ScrollToHorizontalOffset(500);

but the ScrollToHorizontalOffset is still not working. If I do it afterwards, on another user button click it works though. :/

Anyone has a clue?


Nevermind... My error, the example above works. In my project I was basing the ScrollToHorizontalOffset on the img1.ActualWidth which was not updated.

Sorry :/

0

精彩评论

暂无评论...
验证码 换一张
取 消