开发者

Silverlight anchor tag functionality?

I have a a bunch of user controls(about 15, one for each record) in a stackpanel that extends way down my page. I put this in a scrollviewer so that the user wouldn't have to scroll the browser but instead can just scroll the scrollviewer panel.

ANyone know how to programatically scroll to a specific user control in my stack panel. I want a dropdown at the top toi represetn each record so that when selected the scroll viewer scrolls to that user control.

ANy thoughts? I see tha开发者_如何学Got the scrollviewer has a ScrollToVerticalOffset() method but I don't know how I would calculate the offset of these controls in the stackpanel.

Thanks!


I imagine something like the following would work:

void ScrollToUserControl(UserControl uc)
{
    double amountToScroll = 0;
    for (int i = 0; i < stackPanel.Children.Count; i++)
    {
        if (stackPanel.Children[i] == uc)
            break;

        amountToScroll += stackPanel.Children[i].ActualHeight;

    }

    scrollViewer.UpdateLayout();
    scrollViewer.ScrollToVerticalOffset(amountToScroll);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜