Windows Phone 7 ScrollView?
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 UIElement
s 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 UIElement
s, including ContentPanel, be placed in the ScrollViewer
.
精彩评论