Reputation: 49
I am currently developing a Windows Phone application and I included an animated splash screen using a popup.
public MainPage()
{
splashPopup = new Popup() { IsOpen = true, Child = new SplashScreenControl() };
bgWorker = new BackgroundWorker();
BgWorker();
InitializeComponent();
}
All of this works fine, but the problem is that when the app is navigated to another screen, the splash screen will show once again, since the screen uses an instance of the MainPage. Is there a way that I could display the splash screen only once?
I tried using a global variable to check whether it was set to true, but failed as it stayed getting initialized back to false. Which other possible way is there?
This is what I tried to do but did not work:
public class MainPage
{
bool splash = false;
public MainPage()
{
if (splash == false)
{
splashPopup = new Popup() { IsOpen = true, Child = new SplashScreenControl() };
bgWorker = new BackgroundWorker();
BgWorker();
}
InitializeComponent();
splash = true;
}
}
Upvotes: 0
Views: 1400
Reputation: 16826
Have a global flag, something like bool wasShown;
and set it to true whenever the application first loads. Then, in the constructor that you have, check against the flag and if the popup was already shown, do not show it again.
In your code, splash
is not global. It is still present in the context of MainPage. Declare it in the static App
class or use an extra static class. Here is what you should do after that:
public class MainPage
{
public MainPage()
{
if (!App.Splash)
{
splashPopup = new Popup() { IsOpen = true, Child = new SplashScreenControl() };
bgWorker = new BackgroundWorker();
BgWorker();
App.Splash = true;
}
InitializeComponent();
}
}
Upvotes: 2