Custom splash screen page for Windows Phone applications
kiran10182
(Talk | contribs) m (Kiran10182 - - →Introduction) |
|||
| (6 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Windows Phone]][[Category:UI]][[Category:Silverlight]][[Category:Code Examples]] | [[Category:Windows Phone]][[Category:UI]][[Category:Silverlight]][[Category:Code Examples]] | ||
| − | {{Abstract|This article explains how to create | + | {{Abstract|This article explains how to create a custom splash screen for your Windows Phone application.}}<br /> |
{{ArticleMetaData <!-- v1.2 --> | {{ArticleMetaData <!-- v1.2 --> | ||
|sourcecode= [[File:SplashDemoWinPhone.zip]] | |sourcecode= [[File:SplashDemoWinPhone.zip]] | ||
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| − | |devices= | + | |devices= Windows Phone 8 Emulator |
| − | |sdk= | + | |sdk= Windows Phone 8 |
| − | |platform= | + | |platform= Windows Phone |
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| Line 26: | Line 26: | ||
== Introduction == | == Introduction == | ||
| − | In most cases during the launch of an application, you need to do some background operations such as [http://msdn.microsoft.com/en-us/library/hh221581.aspx making web request], parsing some data or something else and while doing this in background it is necessary to keep the user engaged by showing splash screen. This article helps you to | + | In most cases during the launch of an application, you need to do some background operations such as [http://msdn.microsoft.com/en-us/library/hh221581.aspx making web request], parsing some data or something else and while doing this in background it is necessary to keep the user engaged by showing splash screen. This article helps you to create this splash screen. |
| − | # First create | + | ==Necessary steps== |
| − | # Delete default splash screen image from project | + | # First create a Windows phone Project in visual studio. |
| − | # Your project already contains MainPage.xaml file keep it as it is | + | # Delete default splash screen image from project. |
| + | # Your project already contains MainPage.xaml file, keep it as it is. Add a new Page named SplashPage.xaml in the project, replace the existing xaml file code with following code. | ||
<code xml> | <code xml> | ||
| Line 56: | Line 57: | ||
</code> | </code> | ||
| − | Make sure to set SystemTray.IsVisible | + | Make sure to set {{Icode|shell:SystemTray.IsVisible}} to False for using the full screen to display the image. |
| − | === | + | === Modifying SplashPage.cs === |
| − | Now | + | Now, edit SplashPage.cs file |
| − | # Handle Loaded Event of SplashPage, | + | # Handle the {{Icode|Loaded}} Event of SplashPage - {{Icode|SplashPage_Loaded}}, as shown below, |
<code csharp> | <code csharp> | ||
| Line 111: | Line 112: | ||
</code> | </code> | ||
| − | Please note that SplashPage_Loaded function merely makes an asynchronous | + | Please note that {{Icode|SplashPage_Loaded}} function merely makes an asynchronous HTTP request, and {{Icode|ReceiveResponseCallBack}} is called when the HTTP request returns a response. On receiving a response, the user is navigated to MainPage.xaml. |
[http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.deployment(v=vs.105).aspx deployment.Current.Dispatcher.BeginInvoke] is used to access UI thread. | [http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.deployment(v=vs.105).aspx deployment.Current.Dispatcher.BeginInvoke] is used to access UI thread. | ||
| − | + | Thus in the function, you may add code to perform any necessary background tasks while the splash screen is shown to the user. | |
| − | + | === Modifying MainPage.xaml.cs === | |
| − | From SplashPage user is navigated to MainPage | + | |
| + | From SplashPage the user is navigated to MainPage. Once the MainPage is loaded we should remove the stack entry of the SplashPage from [http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394012(v=vs.92).aspx back stack]. This is done so that SplashScreen isn't considered as a page and the user doesn't navigate back to it by using the back key. To do this we need to modify the file MainPage.xaml.cs as follows. | ||
<code csharp> | <code csharp> | ||
| Line 138: | Line 140: | ||
} | } | ||
</code> | </code> | ||
| + | === ModifyingWMAppManifest=== | ||
| + | |||
| + | The last step is to add SplashPage.xaml in the Navigation Page tab of WMAppManifest.xml file. This is done so that the user is shown the splash screen when the application is launched. | ||
| − | + | == Sample Code== | |
| + | Sample project demonstrated in this article is available for download here: [[Media:SplashDemoWinPhone.zip]] | ||
Revision as of 09:53, 7 November 2012
This article explains how to create a custom splash screen for your Windows Phone application.
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Introduction
In most cases during the launch of an application, you need to do some background operations such as making web request, parsing some data or something else and while doing this in background it is necessary to keep the user engaged by showing splash screen. This article helps you to create this splash screen.
Necessary steps
- First create a Windows phone Project in visual studio.
- Delete default splash screen image from project.
- Your project already contains MainPage.xaml file, keep it as it is. Add a new Page named SplashPage.xaml in the project, replace the existing xaml file code with following code.
<phone:PhoneApplicationPage
x:Class="WindowsPhoneSample5.SplashPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="False">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Image Source="/splash.jpg" Stretch="Fill"/>
</Grid>
</phone:PhoneApplicationPage>
Make sure to set shell:SystemTray.IsVisible to False for using the full screen to display the image.
Modifying SplashPage.cs
Now, edit SplashPage.cs file
- Handle the Loaded Event of SplashPage - SplashPage_Loaded, as shown below,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO;
namespace WindowsPhoneSample5
{
public partial class SplashPage : PhoneApplicationPage
{
private HttpWebRequest request;
public SplashPage()
{
InitializeComponent();
Loaded += SplashPage_Loaded;
}
void SplashPage_Loaded(object sender, RoutedEventArgs e)
{
request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://www.developer.nokia.com/Community/Wiki/Portal:Windows_Phone_UI_Articles"));
request.BeginGetResponse(new AsyncCallback(ReceiveResponseCallBack), null);
}
private void ReceiveResponseCallBack(IAsyncResult result)
{
HttpWebResponse response = (HttpWebResponse)this.request.EndGetResponse(result);
using (var stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string str = reader.ReadToEnd();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
});
}
}
}
}
}
Please note that SplashPage_Loaded function merely makes an asynchronous HTTP request, and ReceiveResponseCallBack is called when the HTTP request returns a response. On receiving a response, the user is navigated to MainPage.xaml. deployment.Current.Dispatcher.BeginInvoke is used to access UI thread. Thus in the function, you may add code to perform any necessary background tasks while the splash screen is shown to the user.
Modifying MainPage.xaml.cs
From SplashPage the user is navigated to MainPage. Once the MainPage is loaded we should remove the stack entry of the SplashPage from back stack. This is done so that SplashScreen isn't considered as a page and the user doesn't navigate back to it by using the back key. To do this we need to modify the file MainPage.xaml.cs as follows.
namespace WindowsPhoneSample5
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
NavigationService.RemoveBackEntry();
}
}
}
ModifyingWMAppManifest
The last step is to add SplashPage.xaml in the Navigation Page tab of WMAppManifest.xml file. This is done so that the user is shown the splash screen when the application is launched.
Sample Code
Sample project demonstrated in this article is available for download here: Media:SplashDemoWinPhone.zip

