Domanda

I'm creating a C# Windows 8 Store Application using the Windows Store Grid App (xaml) templates which I edit. My first page, a GroupedItemsPage template, is the Drinks page. Here I've edited the SimpleDataSource method in the SimpleDataSource.cs file to add my own Images and titles (Booze, Soda, ...). These are standard items so I did it there.

Hub Page

When clicked on Booze the user goes to the Booze Page, which is also a GroupedItemsPage template. These 8 items (beer, wine, cocktails, ...) are also standard so I've created a second method in the SimpleDataSource.cs file to shown the correct titles and images. Here it goes wrong. When clicked on "Booze" I get an "System.ArgumentException". I've created another public sealed class SampleDataSourceSecond just like the one in the template. I also edited the LoadState method of that page.

    protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
    {
        // TODO: Assign a collection of bindable groups to this.DefaultViewModel["Groups"]
        var sampleDataGroupsSecond = SampleDataSourceSecond.GetGroupsSecond((String)navigationParameter);
        this.DefaultViewModel["GroupsSecond"] = sampleDataGroupsSecond;
    }

When I'm looking at the xaml page in Visual Studio it displays correct but on runtime the error comes.

Drinks Page

When clicked on "Beer" it goes to another page, the GroupDetailPage template. The items "Jupiler", "Stella" should come from an RSS feed where i get the Title, Description, Image. This is the second problem: because these are not standard I can't change this in the SampleDataSource.cs file. Where should I do this?

Beer Page

So: 1. Am I doing this right? 2. How do I get this Systemt.ArgumentException solved? 3. Where should I place the code so I can fill the GroupDetailPage from an RSS feed.

Thanks in advance!

EDIT: Items from the 2nd page can change. When clicked on Booze it should display on the second page: beer, wine, cocktail, whisky, ... When clicked on Soda: Coca-cola, Icetea, Spriten ...

È stato utile?

Soluzione

In general, the out-of-the-box templates are great as a pattern but rarely as your implementation.

  1. I'm assuming you're getting the exception on the first line of code in the following method?

    public static IEnumerable<SampleDataGroupSecond> GetGroups(string uniqueId)
    {
        if (!uniqueId.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups");
    
        return _sampleDataSource.AllGroups;
    }
    

    You're trying to mold a sample datasource into something that's not really appropriate for your data model needs. The implementation of this data source is explicitly indicating it's not set up to be used in the way you're trying to use it. If I understand correctly, you actually have groups of groups?

  2. Again, the underlying datasource is a sample AND that sample includes three primary fields in the data model: Image, Title and Subtitle. Through XAML databinding, the sample data template (Standard250x250ItemTemplate in StandardStyles.xaml) is handling a very specific and narrow case.

I would start by laying out what your data model actually should look like - forget what's in the sample template. Day 7 of Microsoft's App Builder guidance includes a good section on working with data and files, including data binding which could be helpful to you.

When you master this, you'll realize your question about "where do I place the code is moot." There's rarely ANY code other than what it takes to get the data and assign it to your DataContext.

For RSS specifically, the Blog Reader tutorial should help as well since it's specifically accessing and displaying items from an RSS feed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top