2012年6月6日 星期三

在 Metro App Splash 上加入控制項

在 Windows 8 Metro App 中的設定檔可以指定 Splash 圖片…
除圖片之外還可設定背景顏色…倒是圖片的尺寸有嚴格規定為 620*300
乍看之下會認為 Splash screen 就只能是一張閃過去的 App 圖片…
但像內建的 store 等 App 在 Splash 時會顯示 ProgressRing 又是怎麼辦到的呢…

實際測試了安排一個與 Splash 一模一樣的 Page 可以製造出很相像的結果…
但某些時候還是會出現閃爍的狀況…在 Splash、Page 切換之間閃一下黑幕…
正好在四天前 MSDN 放出了 Splash screen sample…下載回來看了一下…
發現其實 Splash 還真的只能是圖片…無法放額外的控制項…

範例中也是導到新的一頁 Page 物件中…但重點在於 App.xaml.cs 中的這段…

Frame frame = new Frame();
frame.Navigate(typeof(ExtendedSplash), args.SplashScreen);
Window.Current.Content = frame;

在 ExtendedSplash Page 中含有一個 Image 控制項顯示 splash-sdk.png
並在 OnNavigatedTo 時將參數中的 SplashScreen.ImageLocation 做坐標的初始化…
而 ExtendedSplash 是 Page 自然就可以隨意加入控制項嘍…
又因為 Image 的坐標是參考 SplashScreen 之資訊…
所以可以輕易解決此頁圖片因解晰度不同與 Splash 對不到的狀況…

沒有留言:

張貼留言