Silverlight的页面默认是没有上下或左右滑动条的,所以你可能会碰到这种情况,做好了一个Silverlight页面却无法浏览到底部的内容(完整的内容)。所以,我们需要在程序启动前,就把所有的页面都装在一个ScrollViewer里就可以了!
第一个步骤 ,在App.xaml里实现如下代码:
可能为了以后的方面,我们还需要在外层套一层Grid,所以代码变成:
private static Grid gridRoot;
private static ScrollViewer root;
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
gridRoot = new Grid();
root = new ScrollViewer();
root.Content = new MainPage();
gridRoot.Children.Add(root);
this.RootVisual = gridRoot;
}
public static void Navigate(UserControl newPage)
{
root = new ScrollViewer();
root.Content = newPage;
gridRoot.Children.Clear();
gridRoot.Children.Add(root);
}
程序启动后,会先加载MainPage.xaml
这时候,你就发现MainPage里已经有滑动条了
如果要在MainPage里导航到其他页面,那么使用下面的代码就可以了:
App app = (App)Application.Current;
Page2 ep = new Page2 ();
App.Navigate(ep);
本文介绍如何为Silverlight应用添加滚动条,确保页面内容完整显示。通过修改App.xaml文件,在程序启动时包裹ScrollViewer控件,实现页面滚动功能。此外,还提供了页面间导航的方法。

1644

被折叠的 条评论
为什么被折叠?



