【发布时间】:2018-10-18 02:48:26
【问题描述】:
这是我的 App.xaml.cs
[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 验证 H结果=-2147467261 Message=对象引用未设置为对象的实例。
NavigationService 始终为空。
我该如何解决这个问题?
【问题讨论】:
-
我用你的代码测试过,效果很好。您发布的代码是正确的。我认为问题可能不在这里。您能否分享一个可以重现您的问题的minimal reproducible example?或者您可以使用 Minimal Template 10 项目测试您的代码,它应该能够工作。
-
如果我创建一个新项目,这段代码可以正常工作
标签: c# xaml uwp template10