Windows Phone 7 UI设计:代码隐藏文件和启动画面

openkk 9年前
     <p>如果你有Silverlight和C#开发经验,在Windows Phone 7上进行UI设计时,Windows Phone 7应用程序开发平台“Silverlight for Windows Phone”是Silverlight程序员必备的工具,熟悉Silverlight for Windows Phone之后同样还需要熟悉App.xaml和它的代码隐藏文件App.xaml.cs,C#代码增加了一些与手机相关的初始化代码,App类使用公共 RootFrame属性对根框架提供了简单的访问。</p>    <pre class="brush:csharp; toolbar: true; auto-links: false;">public PhoneApplicationFrame RootFrame { get; private set; }</pre>    <p></p>    <p>PhoneApplicationFrame指的是 MicrosoftPhone.Controls.PhoneApplicationFrame,App.xaml.cs使用 Microsoft.Phone.Controls和Microsoft.Phone.Shell命名空间,App类构造函数调用 IntializePhoneApplication方法,它增加了电话相关的代码以显示启动画面,下面的代码片段显示了经典的Silverlight初始化和新的与手机相关的方法:</p>    <pre class="brush:csharp; toolbar: true; auto-links: false;">public App()      {        // Global handler for uncaught exceptions.        // Note that exceptions thrown by ApplicationBarItem.Click        // will not get caught here.        UnhandledException += Application_UnhandledException;        // Standard Silverlight initialization        InitializeComponent();        // Phone-specific initialization        InitializePhoneApplication();      }    </pre>    <p></p>    <p>下面的代码显示了InitializePhoneApplication和CompleteInitializePhoneApplication 方法,InitializePhoneApplication方法创建新的框架,并在其中显示启动画面,直到应用程序启动完毕,CompleteInitializePhoneApplication方法将新框架设置为RootVisual,因为它要连接 RootFrame.Navigated的事件处理程序,注意,不要修改这些方法:</p>    <pre class="brush:csharp; toolbar: true; auto-links: false;">private bool phoneApplicationInitialized = false;        // Do not add any additional code to this method        private void InitializePhoneApplication()        {        if (phoneApplicationInitialized)        return;        // Create the frame but don't set it as RootVisual yet;        // this allows the splash screen to remain active until the        // application is ready to render.        RootFrame = new PhoneApplicationFrame();        RootFrame.Navigated += CompleteInitializePhoneApplication;        // Handle navigation failures        RootFrame.NavigationFailed += RootFrame_NavigationFailed;        // Ensure we don't initialize again        phoneApplicationInitialized = true;        }        // Do not add any additional code to this method        private void CompleteInitializePhoneApplication(object sender,        NavigationEventArgs e)        {        // Set the root visual to allow the application to render        if (RootVisual != RootFrame)        RootVisual = RootFrame;        // Remove this handler since it is no longer needed        RootFrame.Navigated -= CompleteInitializePhoneApplication;      }</pre>    <p></p>    <p>当应用程序加载时,模拟器和设备要显示启动画面,启动画面是一个包含在项目中的24位色深,800x480像素的位图文件 - SplashScreenImage.jpg,你可以用自己的jpeg文件替换它,但注意不能修改名字,只能是 SplashScreenImage.jpg,图1和图2分别显示了默认和自定义启动画面。</p>    <p><a href="https://simg.open-open.com/show/4b9f158d40c8b904a85d8d27ef060c30.jpg" rel="nofollow" target="_blank"><img alt="Windows Phone 7 UI设计:代码隐藏文件和启动画面" src="https://simg.open-open.com/show/4b9f158d40c8b904a85d8d27ef060c30.jpg" width="459" height="617" /></a><br /> <span style="font-size:smaller;"><strong><span style="font-size:x-small;">图 1 默认的位图文件SplashScreenImage.jpg</span></strong></span></p>    <p><a href="https://simg.open-open.com/show/817180755c722e2ec4425de216ad487b.jpg" rel="nofollow" target="_blank"><img alt="Windows Phone 7 UI设计:代码隐藏文件和启动画面" src="https://simg.open-open.com/show/817180755c722e2ec4425de216ad487b.jpg" width="542" height="595" /></a><br /> <strong><span style="font-size:smaller;"><span style="font-size:x-small;">图 2 自定义位图文件SplashScreenImage.jpg</span></span></strong></p>    <p>启动画面必须是24位色深,分辨率为800x480像素的jpeg格式文件,如果使用PNG文件代替,将不会显示启动画面,设计自定义启动画面时要注意,用户是可以旋转设备的。</p>    <p>原文出处:<span style="color:#0000ff;"><u><em><a href="/misc/goto?guid=4959500088107571444" rel="nofollow">http://www.drdobbs.com/windows/227701092</a></em></u></span></p>