这是我的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 verificata =-2147467261 Message=Object引用未设置为对象的实例。
NavigationService总是空的。
我怎么才能解决这个问题?
发布于 2018-10-17 18:48:26
当我将项目的Target版本更新为秋季创建者更新(请参阅project properties)时,我也遇到了同样的问题。
在阅读这线程之后,我通过将Newtonsoft.Json Nuget依赖关系从11.x.x版本更新到10.0.3来修复这个问题。
因此,为了明确起见,我降低了Newtonsoft.Json Nuget依赖项的版本。
发布于 2017-02-22 10:43:30
我也有过类似的问题,但在ViewModel内部,而不是在App.xaml.cs。
因此,当我在视图后面的代码中将NavigationService定义为属性并将其初始化为属性时,ViewModel是空的。
解决方案是在xaml (<Page.DataContext>)中定义<Page.DataContext>,然后一切都像魅力一样工作。
发布于 2018-05-09 11:25:36
对于任何回到这个话题的人,我都会遇到问题,并意识到如果我保留了项目10586的最低版本,问题就会消失。
https://stackoverflow.com/questions/39479706
复制相似问题