开发者

WP7 ScrollViewer - leave viewer at the position scrolled to

开发者 https://www.devze.com 2023-04-01 03:52 出处:网络
this may be a stupid question... but I have a simple TextBlock nested within a ScrollViewer. When the user scrolls up, the content moves, but then snaps back to default position when you stop scrollin

this may be a stupid question... but I have a simple TextBlock nested within a ScrollViewer. When the user scrolls up, the content moves, but then snaps back to default position when you stop scrolling and remove your finger. How can I set up the ScrollViewer so that the textblock stays at the positi开发者_如何学运维on it was scrolled to, without snapping back?

<ScrollViewer>
         <TextBlock Height="500" HorizontalAlignment="Left" Margin="130,529,0,0" Name="statusTextBlock" Text="TextBlock" VerticalAlignment="Top" Width="298" TextWrapping="Wrap" />
</ScrollViewer>

Many thanks!

EDIT:

Based on a suggestion, I wrapped the ScrollViewer in a Grid. This did not help - the text still snaps back to the original position when you release your finger from the scroll action.

<ScrollViewer Margin="130,540,0,0">
      <Grid Height="500" > 
              <TextBlock HorizontalAlignment="Left"  Name="statusTextBlock" Text="TextBlock" VerticalAlignment="Top" TextWrapping="Wrap" />
      </Grid>
</ScrollViewer>


I did not find such issue with TextBlock here. My device is updated with Mango build and the Windows Phone SDK 7.1 RC is installed in my machine.


Wrap the TextBlock in a Grid, and set the height (if necessary) on the Grid. Also, I wouldn't recommend using a static width for a TextBlock. Specially not when using Wrapping. You're not accounting for future screen sizes, which is a bad thing™.

<ScrollViewer>
    <Grid Height="500">
        <TextBlock HorizontalAlignment="Left" Margin="130,529,0,0" Name="statusTextBlock" Text="TextBlock" VerticalAlignment="Top" Width="298" TextWrapping="Wrap" />
    </Grid>
</ScrollViewer>

Update

I can't re-create your problem. Here's an example that works just fine:

<Grid x:Name="ContentPanel"
        Grid.Row="1"
        Margin="12,0,12,0">
    <ScrollViewer>
        <Grid>
            <TextBlock Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sagittis auctor quam ac dictum. Nam tincidunt nisl id turpis dignissim fringilla. Sed elementum euismod fringilla. Etiam sem sem, congue at euismod ut, blandit vitae metus. Sed venenatis rutrum elit sed vestibulum. Etiam nec tempus massa. Pellentesque leo velit, laoreet nec pulvinar non, tempor et felis. Nunc at pulvinar ipsum. Nullam id lorem id augue viverra elementum sed vitae nibh. Nunc pulvinar purus a est porttitor sit amet rutrum mi eleifend. Praesent vitae urna non est volutpat mattis. Nulla sit amet mollis lectus.  In hac habitasse platea dictumst. Duis viverra, lacus ut sollicitudin auctor, lacus velit elementum turpis, a faucibus nibh velit sed ipsum. Vivamus laoreet purus consectetur dui faucibus in ornare lacus congue. Suspendisse laoreet leo laoreet nisl fermentum ut tempus urna placerat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean sit amet quam odio. Quisque eu mattis mauris. Maecenas congue diam quis magna dignissim a facilisis lectus aliquam. Nunc tristique odio id velit pretium eu scelerisque velit dictum. Cras eget purus massa. Suspendisse potenti. Duis at egestas nunc. Nullam vehicula urna eget neque interdum pellentesque. Nulla non nisl ipsum.  Vestibulum congue viverra felis quis congue. Duis sodales, odio vitae aliquam euismod, dolor augue iaculis quam, non hendrerit felis metus quis purus. Suspendisse fringilla vulputate tellus ac consequat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus pulvinar accumsan luctus. Nunc vel orci purus, sollicitudin hendrerit orci. Nam commodo, massa volutpat venenatis eleifend, tortor velit tincidunt metus, at molestie felis neque non est. Curabitur lorem est, ullamcorper quis pellentesque et, consequat a tortor. Duis at lorem et erat pretium ultrices. Sed fringilla neque nec ante interdum ultricies. In facilisis augue eget nisi porttitor in semper risus vulputate. Suspendisse id mi velit. Pellentesque in libero ac neque ullamcorper vulputate interdum pharetra ligula. Pellentesque ac diam justo. Maecenas augue est, tincidunt vel lobortis in, condimentum nec felis.  Morbi sodales luctus velit, in fringilla augue consectetur sed. Pellentesque ut sodales augue. Etiam et sem lacus. Nullam at erat lectus, lobortis vulputate augue. Curabitur nec risus blandit libero ornare posuere quis ac mi. Quisque sed odio tellus, eu vehicula dolor. Aenean luctus pellentesque rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Aliquam eget augue quis ligula adipiscing molestie. Suspendisse ac dictum lorem. Vivamus lacus diam, tincidunt ut sagittis non, consectetur ut magna. Maecenas lectus lectus, suscipit vitae commodo nec, mollis id nibh. Curabitur venenatis posuere ipsum, nec tincidunt tortor pulvinar vel. Vestibulum metus tortor, gravida eu lacinia ut, mattis sed ante. In eu justo id arcu consectetur molestie. Praesent mattis scelerisque mauris, ac porttitor velit malesuada quis. Etiam elementum sem a eros aliquam venenatis eget in tortor. Pellentesque a risus libero. Donec erat diam, porta id blandit vel, vulputate ac diam."
                        TextWrapping="Wrap" />
        </Grid>
    </ScrollViewer>
</Grid>
0

精彩评论

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