我正在使用windows template studio
创建我的应用程序,并希望添加引用extended splash screen
显示初始屏幕以延长时间。
对于在 Windows 模板工作室中以App.xaml.cs
编写的代码,他们使用 ActivationService
.我不知道如何正确添加extended splash
。
有人可以帮忙吗?
如何将延长的启动画面添加到窗口模板工作室?
您可以尝试编辑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;
}
上面的答案有一些问题:
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;
}
}
从"激活服务"中删除"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();
}
现在,完成了。其实还是有一些问题,英语不好,所以我就不说了。以上所有内容均使用翻译软件进行翻译。