微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何给Silverlight页面添加滑动条

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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐