發表文章

目前顯示的是 5月, 2012的文章

如何在Silverlight中建立預設頁面

Silverlight 建立UI的方式,是透過 Application.RootVisual 屬性指定要載入的XAML 檔案。 所以,開啟一個基本的 Silverlgiht 專案來看,在  App.xaml.cs  中Application_Startup,指定了這程式會載入哪個 XAML 頁面當成主要的程式介面: private void Application_Startup( object sender, StartupEventArgs e) {       this .RootVisual = new MainPage (); } 在 App(繼承Application) 中的 this.RootVisual  就是  Application.Current.RootVisual 。 而在 MainPage (繼承UserControl) 類別中,就有包含XAML定義,因此,指定此類別後,RootVisual實際會載入類別中的的 content 對象。 如果想改變載入的畫面,就可以修改指定給 RootVisual 的類別名稱。 例如:       根據使用者選擇,開啟不同頁面: private void  Application_Startup( object  sender,  StartupEventArgs  e) { switch  (selection) { case  1: this .RootVisual =  new   PageStyle1 ();            break ;        default :            this .RootVisual =  new   PageStyle2 ();     } } ------------------------------------------------------------------- 註: Application.RootVisual 只能夠指定一次來源。