繁体   English   中英

Windows Store App 8.1崩溃。 PRISM

[英]Windows Store App 8.1 Crashes. PRISM

我正在从“ PRISM for Windows runtime 8.1”创建一个新项目。 每次我尝试单击设置超级按钮时,应用程序崩溃。 但是从8.0创建新项目不会使应用程序崩溃。 有人知道如何解决这个问题吗?

我得到的错误是

消息=“ System.NullReferenceException:对象引用未设置为对象的实例。\\ r \\ n在Microsoft.Practices.Prism.StoreApps.MvvmAppBase.OnCommandsRequested(SettingsPane发送者,SettingsPaneCommandsRequestedEventArgs args)”

编辑:这是当崩溃时自动生成的文件。

namespace TestApp
{
#if !DISABLE_XAML_GENERATED_MAIN
    public static class Program
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        static void Main(string[] args)
        {
            global::Windows.UI.Xaml.Application.Start((p) => new App());
        }
    }
#endif

    partial class App : global::Microsoft.Practices.Prism.StoreApps.MvvmAppBase
    {
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        private bool _contentLoaded;

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent()
        {
            if (_contentLoaded)
                return;

            _contentLoaded = true;
#if DEBUG && !DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT
            DebugSettings.BindingFailed += (sender, args) =>
            {
                global::System.Diagnostics.Debug.WriteLine(args.Message);
            };
#endif
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break(); <---- the debugger stays on this line.
            };
#endif
        }
    }
}

从项目站点下载开源项目。 然后在VS中,选择将现有项目添加到您的解决方案,并添加Prism for win rt。 现在,您可以编辑并修复该错误。 在MvvmAppBase.cs中,第284行在此处添加空检查。

private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    if (args == null || args.Request == null || args.Request.ApplicationCommands == null)
    {
        return;
    }

    var applicationCommands = args.Request.ApplicationCommands;
    var settingsCommands = GetSettingsCommands();
    if (settingsCommands == null) { return; }
    foreach (var settingsCommand in settingsCommands)
    {
        applicationCommands.Add(settingsCommand);
    }
}

正如ClevelandBuckeye指出的那样,Prism代码中确实存在一个错误,该错误无法处理未配置任何设置的情况。

不过,您不必修复其源代码,只需在App类中重写GetSettingsCommands,然后返回空命令列表,如下所示:

protected override IList<SettingsCommand> GetSettingsCommands()
{
    return new List<SettingsCommand>();
}

如果要查看如何完全实现此示例,请在此处查看AdventureWorks参考实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM