简体   繁体   English

Windows Store App 8.1崩溃。 PRISM

[英]Windows Store App 8.1 Crashes. PRISM

I'm creating a new project from the "PRISM for windows runtime 8.1". 我正在从“ PRISM for Windows runtime 8.1”创建一个新项目。 And every time i'm trying to click on the settings charm the application crashes. 每次我尝试单击设置超级按钮时,应用程序崩溃。 But creating a new project from the 8.0 doesnt crash the app. 但是从8.0创建新项目不会使应用程序崩溃。 Anybody knows how to fix this? 有人知道如何解决这个问题吗?

The error i get is 我得到的错误是

Message = "System.NullReferenceException: Object reference not set to an instance of an object.\\r\\n at Microsoft.Practices.Prism.StoreApps.MvvmAppBase.OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)" 消息=“ System.NullReferenceException:对象引用未设置为对象的实例。\\ r \\ n在Microsoft.Practices.Prism.StoreApps.MvvmAppBase.OnCommandsRequested(SettingsPane发送者,SettingsPaneCommandsRequestedEventArgs args)”

Edit: This is a file that autogenerated when crash. 编辑:这是当崩溃时自动生成的文件。

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
        }
    }
}

Download the open source project from the project site. 从项目站点下载开源项目。 Then in VS choose to add an existing project to your solution and add Prism for win rt. 然后在VS中,选择将现有项目添加到您的解决方案,并添加Prism for win rt。 Now you can edit and fix the bug. 现在,您可以编辑并修复该错误。 In MvvmAppBase.cs, line 284 add a null check here. 在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);
    }
}

As ClevelandBuckeye is pointing out, it does look like there is a bug in the Prism code where it doesn't handle the case when no settings have been configured. 正如ClevelandBuckeye指出的那样,Prism代码中确实存在一个错误,该错误无法处理未配置任何设置的情况。

You don't have to fix up their source code though, just override GetSettingsCommands in your App class, and return an empty list of commands, like this: 不过,您不必修复其源代码,只需在App类中重写GetSettingsCommands,然后返回空命令列表,如下所示:

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

If you want to see an example of how this can be fully implemented, have a look at the AdventureWorks reference implementation here . 如果要查看如何完全实现此示例,请在此处查看AdventureWorks参考实现。

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

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