开发者

Windows Phone 7 ScrollView?

开发者 https://www.devze.com 2023-04-10 00:17 出处:网络
Is there a scrollView in phone7? I have this code private void button8_Click(object sender, RoutedEventArgs e)

Is there a scrollView in phone7?

I have this code

private void button8_Click(object sender, RoutedEventArgs e)
{
    for (int i=0; i<23; i++) {
        Button btn = new Button() { 
            Content="newbutton "+i, 
            HorizontalAlignment =HorizontalAlignment.Left,
            VerticalAlignment = VerticalAlignment.Top,
            Margi开发者_StackOverflow社区n = new Thickness(0, 20+(i*60), 0, 0), 
        };
        btn.Click += new RoutedEventHandler(btn_click);

        ContentPanel.Children.Add(btn);
    }
}

to add 23 buttons to my screen, what is the way to scrolling down the page to show all of the 23 buttons?


I'm assuming ContentPanel is a StackPanel.

In XAML:

<ScrollViewer>
  <StackPanel x:Name="ContentPanel" />
</ScrollViewer>

You can use the ScrollViewer.ScrollToVerticalOffset method to scroll to the end of the page.

However, if you have other UIElements above the ScrollViewer those will still occupy the top of your screen with only the section occupied by the ScrollViewer being scrolled. To prevent that you'll have to have all the UIElements, including ContentPanel, be placed in the ScrollViewer.

0

精彩评论

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

关注公众号