开发者

Silverlight: Auto Scrolling down with Scrollviewer

I have a scrollviewer with dynamic content. On an event, a new content is made visible an开发者_运维技巧d the scrollbar appears. How do i make it auto scroll to have that content in view?

Thanks, Shawn Mclean


Use ScrollToVerticalOffset() to do this, passing in the coordinates of the new content.

var newContent = GetNewContent();

var generalTransform = newContent.TransformToVisual(
    Application.Current.RootVisual as UIElement);

Point offset = generalTransform.Transform(new Point(0, 0));
double controlTop = offset.Y;
double controlLeft = offset.X;

scrollViewer.ScrollToVerticalOffSet(controlTop);
scrollViewer.ScrollToHorizontalOffSet(controlLeft);


Are you sure Scrollviewer is the control you need here?

Sounds to me like you ought to be using ListBox (which you can heavily style if necessary). It has a ScrollIntoView(item) method which would acheive your goal.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜