Vincent
Vincent

Reputation: 3304

How to add extended splash to windows template studio?

I'm using windows template studio to create my app, and want to add a extended splash screen refered Display a splash screen for more time.

For the code write in App.xaml.cs in windows template studio, they use ActivationService. I don't know how to add the extended splash properly.

Is any one can help?

Upvotes: 0

Views: 302

Answers (2)

zhijun yang
zhijun yang

Reputation: 11

There are some problem with the above answer:

1, can lead to the inability to handle other services, such as Toast.

2, causing the theme settings to be invalid, can only follow the system theme. This is my solution:

 if ((activationArgs as IActivatedEventArgs).Kind == ActivationKind.Launch)
 {
     if ((activationArgs as LaunchActivatedEventArgs).PreviousExecutionState != ApplicationExecutionState.Running)
     {
       bool loadState = ((activationArgs as LaunchActivatedEventArgs).PreviousExecutionState == ApplicationExecutionState.Terminated);
       ExtendedSplash extendedSplash = new ExtendedSplash((activationArgs as LaunchActivatedEventArgs).SplashScreen, loadState);
       var rootFrame = new Frame();
       rootFrame.Content = extendedSplash;
       Window.Current.Content = rootFrame;
      }
  }

Remove "InitializeAsync()" from "ActivationService".Add to ExtendedSplash.xaml.cs. Here,in order to avoid the window being activated when the picture is loading, write it in the "ImageOpened" event.

private async void ExtendedSplashImage_ImageOpened(object sender, RoutedEventArgs e)
{
     Window.Current.Activate();
     if (splash != null)
     {
        splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);

        splashImageRect = splash.ImageLocation;

        PositionImage();
        PositionRing();
     }
     rootFrame = new Frame();

     //place it here
     await InitializeAsync();
 }

 private async Task InitializeAsync()
 {
      // 
      await ThemeSelectorService.InitializeAsync();           

      DismissExtendedSplash();

      // Must be behind “DismissExtendedSplash()”
      await ThemeSelectorService.SetRequestedThemeAsync();
 }

Now,finished.In fact, there are still some problems, English is not good, so I will not say it. All of the above are translated using translation software.

Upvotes: 1

Nico Zhu
Nico Zhu

Reputation: 32775

How to add extended splash to windows template studio?

You could try to edit ActivationService like the follow

public async Task ActivateAsync(object activationArgs)
{
    if (IsInteractive(activationArgs))
    {
        // Initialize things like registering background task before the app is loaded
        await InitializeAsync();

        if ((activationArgs as LaunchActivatedEventArgs).PreviousExecutionState != ApplicationExecutionState.Running)
        {
            bool loadState = ((activationArgs as LaunchActivatedEventArgs).PreviousExecutionState == ApplicationExecutionState.Terminated);
            ExtendedSplash extendedSplash = new ExtendedSplash((activationArgs as LaunchActivatedEventArgs).SplashScreen, loadState);
            var rootFrame = new Frame();
            rootFrame.Content = extendedSplash;
            Window.Current.Content = rootFrame;
        }

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (Window.Current.Content == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            Window.Current.Content = _shell?.Value ?? new Frame();
        }
    }

    await HandleActivationAsync(activationArgs);
    _lastActivationArgs = activationArgs;


    if (IsInteractive(activationArgs))
    {
        // Ensure the current window is active
        Window.Current.Activate();

        // Tasks after activation
        await StartupAsync();
    }
}

ExtendedSplash

void DismissExtendedSplash()
{
    // Navigate to mainpage
    rootFrame.Navigate(typeof(ShellPage));
    // Place the frame in the current Window
    Window.Current.Content = rootFrame;
}

Upvotes: 1

Related Questions