0

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

App.xaml.cs对于在 windows 模板工作室中编写的代码,他们使用ActivationService. 我不知道如何extended splash正确添加。

有没有人可以帮忙?

4

2 回答 2

1

如何将扩展启动画面添加到 Windows 模板工作室?

您可以尝试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();
    }
}

扩展飞溅

void DismissExtendedSplash()
{
    // Navigate to mainpage
    rootFrame.Navigate(typeof(ShellPage));
    // Place the frame in the current Window
    Window.Current.Content = rootFrame;
}
于 2019-06-04T08:58:51.887 回答
1

上面的答案有一些问题:

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。这里,为了避免图片加载时窗口被激活,写在“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();
 }

现在,完了。其实还是有一些问题,英文不好,就不说了。以上都是使用翻译软件翻译的。

于 2019-08-05T07:51:48.833 回答