Closed sibille closed 6 years ago
The generated code on App.xaml.cs is
protected override async Task OnInitializeAsync(IActivatedEventArgs args)
{
await Container.Resolve<ILiveTileService>().EnableQueueAsync().ConfigureAwait(false);
WindowManagerService.Current.Initialize();
await ThemeSelectorService.InitializeAsync().ConfigureAwait(false);
// We are remapping the default ViewNamePage and ViewNamePageViewModel naming to ViewNamePage and ViewNameViewModel to
// gain better code reuse with other frameworks and pages within Windows Template Studio
ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
{
var viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "App109.ViewModels.{0}ViewModel, App109", viewType.Name.Substring(0, viewType.Name.Length - 4));
return Type.GetType(viewModelTypeName);
});
await base.OnInitializeAsync(args);
}
Changing the execution order to the following solves the problem and would actually be better, as ThemeSelectorSevice should be initialized early to ensure correct theme is shown from the start
protected override async Task OnInitializeAsync(IActivatedEventArgs args
{
WindowManagerService.Current.Initialize();
await ThemeSelectorService.InitializeAsync().ConfigureAwait(false);
// We are remapping the default ViewNamePage and ViewNamePageViewModel naming to ViewNamePage and ViewNameViewModel to
// gain better code reuse with other frameworks and pages within Windows Template Studio
ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
{
var viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "App109.ViewModels.{0}ViewModel, App109", viewType.Name.Substring(0, viewType.Name.Length - 4));
return Type.GetType(viewModelTypeName);
});
await Container.Resolve<ILiveTileService>().EnableQueueAsync().ConfigureAwait(false);
await base.OnInitializeAsync(args);
}
@LeeParrishMSFT and @milazzom, I'll prepare a PR for this, could you review?
@sibille I'm checking it out.
Talking with @milazzom and @sibille, @milazzom has a more robust solution here. We should do that along with the reordering.
I suggest we add a comment for these two lines of code for all frameworks that basically is
// These are initializing the window and setting the theme, they should be the first two items done else you may get a flickering for setting theming / delay in window creation. WindowManagerService.Current.Initialize(); await ThemeSelectorService.InitializeAsync().ConfigureAwait(false);
@crutkas, you can have multiview and themeselection or any of the two separately, we'll have to do two separate comments, like this:
//This is initializing the window manager service, make sure this is one of the first calls to avoid delay in window creation WindowManagerService.Current.Initialize(); //This is setting the theme, make sure this is one of the first calls to avoid flickering. await ThemeSelectorService.InitializeAsync().ConfigureAwait(false);
Verified in dev-nightly: Templates version: 0.18.18255.1 Wizard version: 0.18.18255.1
Repro steps:
Result: App crashes with error "Element not found. (Exception from HRESULT: 0x80070490)" at Windows.UI.ViewManagement.ApplicationView.GetForCurrentView()
Version: Templates version: 0.18.18242.2 Wizard version: 0.18.18242.1