简体   繁体   中英

WP8.1 app crashes when navigating to another page

It's a data-bound windows phone 8.1 (universal) app. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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