How do I create a Splash Screen in my application?
I would like examples!
How do I create a Splash Screen in my application?
I would like examples!
See this article Creating an Opening Screen for Windows Phone ( Msdn - English ).
Free Translation:
If you are using a single image, you must add an image file that is
768×1280
namedSplashScreenImage.jpg
to your project. The phone automatically scales the image to the correct size. If you want to provide pixel-perfect home screens for all resolutions, you can add the following images to the root folder of your application project.
WVGA 480×800 SplashScreenImage.screen-WVGA.jpg
WXGA 768×1,280 SplashScreenImage.screen-WXGA.jpg
720p 720x1,280 SplashScreenImage.screen-720p.jpg
Each new Windows Phone OS 7.1 project includes a SplashScreenImage.jpg file. To customize the home screen, you can replace your own image with the default image. You can replace the default image with any image you choose, but it must be
480×800
pixels in size, and it should be named SplashScreenImage.jpg . You must set the Build Action property of the image to content.
Here ( Nokia Developer ) there is a example that may be useful to you.
First create a project with Windows Phone Application Template. Create a Windows Phone User Control add a ProgressBar
, TextBlock
, and Image
. The image is the default splash of the project.
<Grid x:Name="LayoutRoot" Background="White" Width="480" Height="800">
<ProgressBar HorizontalAlignment="Left" Margin="47,692,0,89" Name="progressBar1" Width="383" />
<Image Height="512" HorizontalAlignment="Left" Margin="0,0,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="480" Source="SplashScreenImage.jpg" />
<TextBlock HorizontalAlignment="Left" Margin="185,656,0,114" Name="textBlock1" Text="Please Wait..." Width="111" Foreground="Black" FontSize="22" />
</Grid>
In the constructor MainPage.xaml.cs we call the function ShowSplash()
to load the popup.
private void ShowSplash()
{
this.popup = new Popup();
this.popup.Child = new SplashScreenControl();
this.popup.IsOpen = true;
StartLoadingData();
}
We will initialize the Popup
class, and then set the SplashScreenControl
class to be hosted in the popup. IsOpen()
opens the pop-up .
So far the code will load the pop-up with the progress bar.
Now let's add some process in the background, and when the background process is completed, we will close the pop-up, as a result, the user will see the splash screen.
The StartLoadingData()
function starts and completes the background job.
private void StartLoadingData()
{
backroungWorker = new BackgroundWorker();
backroungWorker.DoWork += new DoWorkEventHandler(backroungWorker_DoWork);
backroungWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backroungWorker_RunWorkerCompleted);
backroungWorker.RunWorkerAsync();
}
First let's initialize the class BackgroundWorker
. We call the function RunWorkerAsync()
to start executing a background operation and therefore backroungWorker_DoWork()
is called.
void backroungWorker_DoWork(object sender, DoWorkEventArgs e)
{
//here we can load data
Thread.Sleep(9000);
}
Here we will use the Sleep()
function to wait for some time. When backroungWorker_DoWork()
expires, backroungWorker_RunWorkerCompleted()
is called, which closes the popup.
void backroungWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
this.popup.IsOpen = false;
}
);
}
So the user can see a screen with the progress bar.