简体   繁体   English

导航到另一个页面时WP8.1应用程序崩溃

[英]WP8.1 app crashes when navigating to another page

It's a data-bound windows phone 8.1 (universal) app. 这是一个数据绑定的Windows Phone 8.1(通用)应用程序。 When I navigate to a detailed view of the item from the main page it works like a charm. 当我从主页导航到该项目的详细视图时,它就像一个超级按钮。 When I use the same code to navigate from another page to the same detailed one, my app closes and I get no exception. 当我使用相同的代码从另一页面导航到相同的详细页面时,我的应用程序关闭,我也没有例外。 Code is the same as in the hub default sample when you open a new hub project. 打开新的中心项目时,代码与中心默认示例中的代码相同。 This is the code I use to navigate to he page. 这是我用来导航至页面的代码。

 private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
    {
        {
            // Navigate to the appropriate destination page, configuring the new page
            // by passing required information as a navigation parameter
            var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

            if (!Frame.Navigate(typeof(Session), itemId))
            {
                throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage"));
            }
        }
    }

and this is the code I use to handle the loading 这是我用来处理加载的代码

private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {

        // TODO: Create an appropriate data model for your problem domain to replace the sample data
        var item = await SampleDataSource.GetItemAsync((string)e.NavigationParameter);
        this.DefaultViewModel["Item"] = item;


    }

The code stops after hitting the last bracket and the app exits. 到达最后一个括号后,代码停止运行,应用退出。 Until then it works as it should, the values are correct and it finds the specific item! 在此之前,它可以正常工作,值正确,并且可以找到特定的项目!

Found the solution here and changed my code to 这里找到解决方案并将代码更改为

 private async void ItemView_ItemClick(object sender, ItemClickEventArgs e)
    {
        {

            var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Frame.Navigate(typeof(Session), itemId));


        }
    }

I still don't understand this error, but it is now solved. 我仍然不理解此错误,但现在已解决。

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

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