Welcome

首页 / 软件开发 / .NET编程技术 / Windows 8 Store Apps学习(69) 其它: 自定义启动屏幕,

Windows 8 Store Apps学习(69) 其它: 自定义启动屏幕,2014-09-02重新想象 Windows 8 Store Apps (69) - 其它: 自定义启动屏幕, 程序的运行位置, 保持屏幕的点亮状态, MessageDialog, PopupMenu

作者:webabcd

介绍

重新想象 Windows 8 Store Apps 之 其它

自定义启动屏幕

检查当前呈现的应用程序是运行在本地还是运行在远程桌面或模拟器

保持屏幕的点亮状态

MessageDialog - 信息对话框

PopupMenu - 上下文菜单

示例

1、演示如何自定义启动屏幕

Feature/MySplashScreen.xaml

<Pagex: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.csif (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