Windows 8 Store Apps學習(69) 其它: 自訂啟動螢幕,

來源:互聯網
上載者:User

重新想象 Windows 8 Store Apps (69) - 其它: 自訂啟動螢幕, 程式的運行位置, 保持螢幕的點亮狀態, MessageDialog, PopupMenu

作者:webabcd

介紹

重新想象 Windows 8 Store Apps 之 其它

自訂啟動螢幕

檢查當前呈現的應用程式是運行在本地還是運行在遠端桌面或模擬器

保持螢幕的點亮狀態

MessageDialog - 資訊對話方塊

PopupMenu - 操作功能表

樣本

1、示範如何自訂啟動螢幕

Feature/MySplashScreen.xaml

<Page    x:Class="XamlDemo.Feature.MySplashScreen"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:XamlDemo.Feature"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">        <Grid Background="#1b4b7c">            <Grid.RowDefinitions>            <RowDefinition />            <RowDefinition Height="180" />        </Grid.RowDefinitions>            <Canvas Grid.Row="0">            <Image x:Name="splashImage" Source="/Assets/SplashScreen.png"  />        </Canvas>        <StackPanel Grid.Row="1" HorizontalAlignment="Center">            <ProgressRing IsActive="True"  />            <TextBlock Name="lblMsg" Text="我是自訂啟動頁,1 秒後跳轉到首頁" FontSize="14.667" Margin="0 10 0 0"  />        </StackPanel>                </Grid></Page>

Feature/MySplashScreen.xaml.cs

/* * 示範如何自訂啟動螢幕 *     關聯代碼:App.xaml.cs 中的 override void OnLaunched(LaunchActivatedEventArgs args) *  * 應用情境: * 1、app 的啟動螢幕就是一個圖片加一個背景色,其無法更改, * 2、但是啟動螢幕過後可以參照啟動螢幕做一個內容更豐富的自訂啟動螢幕 * 3、在自訂啟動螢幕顯示後,可以做一些程式的初始化工作,初始化完成後再進入主程式 */    using System.Threading.Tasks;using Windows.ApplicationModel.Activation;using Windows.Foundation;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;    namespace XamlDemo.Feature{    public sealed partial class MySplashScreen : Page    {        /*         * SplashScreen - app 的啟動螢幕對象,在 Application 中的若干事件處理器中的事件參數中均可獲得         *     ImageLocation - app 的啟動螢幕的圖片的位置資訊,返回 Rect 類型對象         *     Dismissed - app 的啟動螢幕關閉時所觸發的事件         */            // app 啟動螢幕的相關資訊        private SplashScreen _splashScreen;            public MySplashScreen()        {            this.InitializeComponent();                lblMsg.Text = "自訂 app 的啟動螢幕,開啟 app 時可看到此頁面的示範";        }            // LaunchActivatedEventArgs 來源於 App.xaml.cs 中的 override void OnLaunched(LaunchActivatedEventArgs args)        public MySplashScreen(LaunchActivatedEventArgs args)        {            this.InitializeComponent();                ImplementCustomSplashScreen(args);        }            private async void ImplementCustomSplashScreen(LaunchActivatedEventArgs args)        {            // 視窗尺寸發生改變時,重新調整自訂啟動螢幕            Window.Current.SizeChanged += Current_SizeChanged;                // 擷取 app 的啟動螢幕的相關資訊            _splashScreen = args.SplashScreen;                // app 的啟動螢幕關閉時所觸發的事件            _splashScreen.Dismissed += splashScreen_Dismissed;                // 擷取 app 啟動螢幕的圖片的位置,並按此位置調整自訂啟動螢幕的圖片的位置            Rect splashImageRect = _splashScreen.ImageLocation;            splashImage.SetValue(Canvas.LeftProperty, splashImageRect.X);            splashImage.SetValue(Canvas.TopProperty, splashImageRect.Y);            splashImage.Height = splashImageRect.Height;            splashImage.Width = splashImageRect.Width;                await Task.Delay(1000);                // 關掉自訂啟動螢幕,跳轉到程式首頁面            var rootFrame = new Frame();            rootFrame.Navigate(typeof(MainPage), args);            Window.Current.Content = rootFrame;            Window.Current.Activate();        }            void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)        {            // 擷取 app 啟動螢幕的圖片的最新位置,並按此位置調整自訂啟動螢幕的圖片的位置            Rect splashImageRect = _splashScreen.ImageLocation;            splashImage.SetValue(Canvas.LeftProperty, splashImageRect.X);            splashImage.SetValue(Canvas.TopProperty, splashImageRect.Y);            splashImage.Height = splashImageRect.Height;            splashImage.Width = splashImageRect.Width;        }            void splashScreen_Dismissed(SplashScreen sender, object args)        {            }    }}

App.xaml.cs

protected async override void OnLaunched(LaunchActivatedEventArgs args){    // 顯示自訂啟動螢幕,參見 Feature/MySplashScreen.xaml.cs    if (args.PreviousExecutionState != ApplicationExecutionState.Running)    {        XamlDemo.Feature.MySplashScreen mySplashScreen = new XamlDemo.Feature.MySplashScreen(args);        Window.Current.Content = mySplashScreen;    }        // 確保當前視窗處於活動狀態    Window.Current.Activate();}

2、示範如何檢查當前呈現的應用程式是運行在本地還是運行在遠端桌面或模擬器

Feature/CheckRunningSource.xaml.cs

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.