locked
item clicked in GroupedItemsPage not shown in ItemDetailsPage from grid project template RRS feed

  • Question

  • I am using the grid template in VS 2012 for my app. Instead of the static data, i fetch the data for the tiles from a web source using async await calls. In the GroupedItemsPage.xaml.cs i call a method LoadData() in SampleDataSource.cs to fetch titles, subtitles of each item in the groups and add them to AllGroups collection. This displays the items on the GroupedItemsPage.xaml and GroupDetailPage.xaml. When any item is clicked from GroupedItemsPage.xaml or GroupDetailPage.xaml, a method GetItem (default with the template) in SampleDataSource.cs is called which fetches the item from the collection. When i get the item in ItemDetailPage.xaml.cs LoadState method, i then call another method in SampleDataSource.cs to fetch content for the item using await and async calls. Then in the LoadState method itself, i update the item in the collection. Then the method exits, but the ItemDetailPage.xaml shows a different item, instead of the updated one with the content.   

    If i remove the part which makes the call to fetch the item content in the ItemDetailPage.xaml.cs LoadState method, then the correct item is displayed in ItemDetailPage.xaml page. But if i add the call to get the content, a different item in the group is displayed. Can someone help me to resolve this issue?

    Thanks!


    • Edited by Sandabh Wednesday, December 26, 2012 7:56 AM spell check
    Wednesday, December 26, 2012 7:53 AM

Answers

  • Though this still didnt work, the work around i did was that i moved the part of getting the item content into item clicked event in GroupedItemsPage.xaml.cs and now i get the correct item.
    • Marked as answer by Sandabh Friday, December 28, 2012 3:53 AM
    Friday, December 28, 2012 3:53 AM

All replies

  • You need be more clear and should show code......

    I created a default grid project.

    In GroupedItemsPages.xaml.cs we have:

    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;
                this.Frame.Navigate(typeof(ItemDetailPage), itemId);
            }

    Like you can see in last line, itemId is sent to the ItemDetailPage, but it looks like you did not change this....i suppose.


    Sara Silva
    My blog | My Windows 8 Store Apps Samples
    Follow me in Twitter @saramgsilva

    My Windows 8 Store Apps: Female Pill | Galinho (Tic tac Toe) | 24
    My Windows Phone Apps

    (If my reply answers your question, please propose it as an answer because it will help other users)



    • Edited by saramgsilva Wednesday, December 26, 2012 10:05 AM
    Wednesday, December 26, 2012 10:04 AM
  • Thanks for the reply Sara. Here is my code for GroupedItemsPage.xaml.cs

    Here i have a sampleDataSourceInstance which is a static instance. I then call LoadData() which gets the title and subtitle for the items and displays correctly on GroupedItemsPage.xaml 

    protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { var sampleDataSource = SampleDataSource.sampleDataSourceInstance; await sampleDataSource.LoadData(); var sampleDataGroups = sampleDataSource.GetGroups((String)navigationParameter); this.DefaultViewModel["Groups"] = sampleDataGroups;

    }

    Here is the code in ItemDetailPage.xaml.cs which calls a method GetContent in sampleDataSourceInstance which gets the content for the particular clicked item

    protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { // Allow saved page state to override the initial item to display if (pageState != null && pageState.ContainsKey("SelectedItem")) { navigationParameter = pageState["SelectedItem"]; } var sampleDataSource = SampleDataSource.sampleDataSourceInstance; var item = sampleDataSource.GetItem((String)navigationParameter); string itemurl = string.empty; string itemcontent = string.empty;

    if(item!=null) { itemurl = item.itemurl; // itemurl is a property in the sampledataitem } itemcontent = await sampleDataSource.GetContent(itemurl); item.content = itemcontent; //update the content of the sampledataitem this.DefaultViewModel["Group"] = item.Group; this.DefaultViewModel["Items"] = item.Group.Items; this.flipView.SelectedItem = item; }


    When i run this, i get the correct item in ItemDetailPage.xaml.cs , but after i exit the above loadstate method, the item displayed is a different item from the same group. If i remove the line "itemcontent = await sampleDataSource.GetContent(itemurl);  ", then the item displayed is the one which was clicked.

    But if i keep the line to fetch the content from the web, the item displayed becomes some other item than the one which was clicked.


    • Edited by Sandabh Wednesday, December 26, 2012 7:24 PM
    Wednesday, December 26, 2012 7:23 PM
  • Though this still didnt work, the work around i did was that i moved the part of getting the item content into item clicked event in GroupedItemsPage.xaml.cs and now i get the correct item.
    • Marked as answer by Sandabh Friday, December 28, 2012 3:53 AM
    Friday, December 28, 2012 3:53 AM