This paper uses WindowsPhone 8 Sdk,vs 2013, this method is also suitable for wp7,wp8.1.
When you create a generic WP8 application, the project directory will default to a picture that appears when the program starts and is named Splashscreenimage.jpg. This is because when the program starts it may take some time to load the first interface, and this picture will appear first. If you want to change the splash screen, you can replace it with a different image of your own definition. But what if you want to show the dynamic effect on the splash screen? Here's a little bit.
In order to display the dynamic interface when the program starts, a page is displayed before mainpage. In other words, remove the previous default splash screen. In order to achieve this effect, we need to remove the splashscreenimage.jpg first. Create a UserControl to display the dynamic effect, and display the UserControl before the Mianpage is displayed. Also control the time it is displayed, and we can control the time. The BackgroundWorker thread is also used here.
Using the BackgroundWorker class, you operate on a separate background thread, while letting WP's render thread and UI thread continue to execute unaffected. When a transaction in a thread finishes processing, it can be fed back to the UI thread.
Note: Do not manipulate any user interface objects in the DoWork event handler function. Of course ProgressChanged and RunWorkerCompleted event callback function, you can manipulate the user interface. The specific use in the following code is explained in detail.
First, create a UserControl, such as:
Add New Item
After you've created it, change it to height =800, weight = 480, or it won't cover the entire screen.
The following is the code for the control's xmal, with comments in the code.
<UserControl x:class="Loadingpage.loadingcontrol" xmlns="Http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" XMLNS:MC="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="D" FontFamily="{StaticResource phonefontfamilynormal}" FontSize="{StaticResource phonefontsizenormal}" Foreground="{StaticResource Phoneforegroundbrush}" D:designheight=" the" D:designwidth="480"> <!--setting width -to- <!--control animation resource definition -- <usercontrol.resources> <!--Use the storyboard -- <Storyboard x:key="Loadanimation"> <doubleanimation from ="0" to ="359" Duration= "0:0:1" RepeatBehavior="Forever"storyboard.targetname="Visualtransform" Storyboard.TargetProperty="Angle"/> </Storyboard> </usercontrol.resources> <Grid x:name="LayoutRoot" Background="{StaticResource Phoneaccentbrush} "> <!--use * to distribute layouts evenly -- <grid.rowdefinitions> <rowdefinition Height="*"/> <rowdefinition Height="*"/> <rowdefinition Height="*"/> <rowdefinition Height="*"/> </grid.rowdefinitions> <TextBlock Text="Loading, please later ..." " grid.row=" 1 " verticalalignment=" Center "horizontalalignment= "Center"/> <!--grid, use path to draw a circle, and the animation is in that grid-- <Gridx:name= "Visual" Margin="0,30,0,0" Rendertransformorigin= "0.5,0.5" grid.row= "2"verticalalignment=" Center " horizontalalignment=" center "> <grid.rendertransform> <transformgroup> <rotatetransform x:name="Visualtransform"/> </transformgroup> </grid.rendertransform> <Path Width= "Height=" " Stretch=" Fill " strokethickness="5"strokestartlinecap= "Round" Data="M1, 0 a1,2,90,1,1,0,0 "> <path.stroke> <LinearGradientBrush StartPoint="1,0.8" EndPoint="0.3,0.1" > <gradientstop Color="White" Offset="0"/> <gradientstop Color="Transparent" Offset="1"/> </LinearGradientBrush> </path.stroke> </Path> </Grid> </Grid></UserControl>
Its CS code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Navigation;usingMicrosoft.Phone.Controls;usingMicrosoft.Phone.Shell;usingSystem.windows.media.animation;namespace loadingpage{ Public Partial classLoadingcontrol:usercontrol { Public Loadingcontrol() {InitializeComponent ();//Set the root grid layout to a wide height for the actual device screenLayoutroot.height = App.Current.Host.Content.ActualHeight; Layoutroot.width = App.Current.Host.Content.ActualWidth;//At Loaded and unloaded, add routed events to start and stop animations This. Loaded + =NewRoutedeventhandler (loadingscreencontrol_loaded); This. Unloaded + =NewRoutedeventhandler (loadingscreencontrol_unloaded); }voidLoadingscreencontrol_unloaded (Objectsender, RoutedEventArgs e) {//Load Animation resourcesStoryboard SB = This. resources["Loadanimation"] asStoryboard;//Stop animationSb. Stop (); }voidLoadingscreencontrol_loaded (Objectsender, RoutedEventArgs e) {//Load Animation resourcesStoryboard SB = This. resources["Loadanimation"] asStoryboard;//Start animationSb. Begin (); } }}
Next, you will add the code to be processed in the mainpage
1. Add the following namespaces in the MainPage.xaml.cs file:
Using System.Threading;
Using System.Windows.Controls.Primitives;
2. Using the Popup class, add UserControl to the popup to make it appear.
3, the use of BackgroundWorker, timing (also can do other initialization operation), let the start screen display a certain time.
4, end, cancel show Popup
Here is the MainPage.xaml.cs code
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Navigation;usingMicrosoft.Phone.Controls;usingMicrosoft.Phone.Shell;usingLoadingpage.resources;usingSystem.Windows.Controls.Primitives;usingSystem.ComponentModel;usingSystem.threading;namespace loadingpage{ Public Partial classMainpage:phoneapplicationpage {//Constructors Public MainPage() {InitializeComponent ();//Call the dynamic loading interface after the home page is initializedLoadwelcomepage ( -);//Sample code for localizing ApplicationBar //buildlocalizedapplicationbar ();}voidLoadwelcomepage (intTime) {//Use popup to loadingcontrol the user control as its childPopup popup =NewPopup (); Loadingcontrol Loadingcontrol =NewLoadingcontrol (); Popup. Child = Loadingcontrol; Popup. IsOpen =true;//Set to True to display //new background threadBackgroundWorker bkw =NewBackgroundWorker ();//need to work in a background thread, note that you cannot manipulate content related to the UI threadbkw. DoWork + = ((s,e) = {Thread.Sleep (time); });//Background thread What to do after the work is donebkw. RunWorkerCompleted + = ((s,e) = { This. Dispatcher.begininvoke (() = {Popup. IsOpen =false}); });//Execute background threadbkw. RunWorkerAsync (); }//Sample code for generating localized ApplicationBar //private void Buildlocalizedapplicationbar () //{ //// Set the ApplicationBar of the page to a new instance of ApplicationBar. //ApplicationBar = new ApplicationBar (); ///// Create a New button and set the text value to the localized string in Appresources. //Applicationbariconbutton Appbarbutton = new Applicationbariconbutton (The new Uri ("/assets/appbar/ Appbar.add.rest.png ", urikind.relative)); //Appbarbutton.text = Appresources.appbarbuttontext; //APPLICATIONBAR.BUTTONS.ADD (Appbarbutton); Create a new menu item with a localized string in Appresources. //Applicationbarmenuitem Appbarmenuitem = new Applicationbarmenuitem (appresources.appbarmenuitemtext); //APPLICATIONBAR.MENUITEMS.ADD (Appbarmenuitem); //}}}
Thread.Sleep () method in using System.Threading; namespaces
BackgroundWorker in using System.Windows.Controls.Primitives; namespaces
At last
If you do not use the popup and UserControl, and create a new page, set its first page, is not also possible. However, this will be recorded by the page stack, when the return operation, it will return to the same page, it lost its meaning. Of course, you can manage the page stack and delete its records, but that's a hassle.
The source is here.
WindowsPhone developing how to create a dynamic boot interface