特別鳴謝“四川省計算機研究院科技人才培訓中心中國頂級RIA、嵌入式培訓機構”提供圖片
成都市成科西路3號
傳真:028-68187983
網站: http://www.tccxfw.com/jiaoyu.html
爲Silverlight 應用程序頁面添加滾動條
當您使用Expression Blend 4 或者 Visual Studio 2010,創建Silverlight 應用程序,並運行它時在瀏覽器中有沒有滾動條,您可能看不到您完整的頁面。
這是一個例子網站,可以看到,滾動條沒有在網頁上,所以基本上無法讀取頁面內容。
要解決此問題,我們需要將 ScrollViewer 或滾動條添加到頁面,這樣做最簡單的方法之一是通過更改在 App.xaml.cs 文件中的 Application_Startup 方法。
默認 Application_Startup 方法,如下:
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
}
現在我們可以做的是,放置一個 ScrollViewer 在網頁。 下面代碼是這樣寫的。
private void Application_Startup(object sender, StartupEventArgs e)
{
ScrollViewer scroller = new ScrollViewer();
scroller.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
scroller.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scroller.Content = new PageSwitcher(); //啓動頁面
this.RootVisual = scroller;
}
現在,如果您在運行應用程序,您會發現這兩個滾動條現在都可見。