如何将扩展启动画面添加到 windows template studio?

How to add extended splash to windows template studio?

我正在使用 windows template studio 创建我的应用程序,并想添加一个 extended splash screen 引用 Display a splash screen for more time

在windows template studio 中App.xaml.cs 中编写的代码,他们使用ActivationService。我不知道如何正确添加 extended splash

有人可以帮忙吗?

How to add extended splash to windows template studio?

您可以尝试像下面这样编辑ActivationService

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;
}

以上回答有问题:

1、会导致无法处理其他服务,比如Toast。

2、导致主题设置无效,只能跟随系统主题。这是我的解决方案:

 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;
      }
  }

从 "ActivationService" 中删除 "InitializeAsync()"。添加到 ExtendedSplash.xaml.cs。这里为了避免window在图片加载时被激活,写在"ImageOpened"事件中。

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();
 }

现在,finished.In其实还是有一些问题,英文不好,就不说了。以上均为使用翻译软件翻译。