我正在使用windows template studio
创建我的应用,并想添加一个引用了Display a splash screen for more time的extended splash screen
。
对于在Windows模板工作室App.xaml.cs
中编写的代码,他们使用ActivationService
。我不知道如何正确添加extended splash
。
有人可以帮忙吗?
答案 0 :(得分: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;
}
答案 1 :(得分: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();
}
现在完成了。实际上,仍然存在一些问题,英语不好,所以我就不说了。以上所有内容均使用翻译软件进行了翻译。