0
这是我App.xaml.csTemplate10的NavigationService为空
[Bindable]
sealed partial class App : Template10.Common.BootStrapper
{
public App()
{
InitializeComponent();
SplashFactory = (e) => new Views.Splash(e);
var _settings = SettingsService.Instance;
RequestedTheme = _settings.AppTheme;
CacheMaxDuration = _settings.CacheMaxDuration;
ShowShellBackButton = _settings.UseShellBackButton;
}
public override async Task OnInitializeAsync(IActivatedEventArgs args)
{
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
var statusBar = StatusBar.GetForCurrentView();
await statusBar.HideAsync();
}
await Task.CompletedTask;
}
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
NavigationService.Navigate(typeof(Views.MainPage)); // Exception here
await Task.CompletedTask;
}
}
每次我启动的应用程序,我得到这个异常:
System.NullReferenceException verificata 的HResult = -2147467261 留言=未将对象引用设置为对象的实例。
NavigationService始终为空。
我该如何解决这个问题?
我用你的代码测试过,它效果很好。你发布的代码是正确的。我认为问题可能不在这里。你能分享一个可以重现你的问题的[mcve]吗?或者你可以用一个Minimal Template 10项目测试你的代码,它应该能够工作。 –
如果我创建一个新项目,此代码工作正常 – frenk91