【问题标题】:Adding a group inside of a group in a "Grid" application for the Windows 8 Store在 Windows 8 应用商店的“网格”应用程序中的组内添加组
【发布时间】:2013-01-10 05:34:00
【问题描述】:

我正在开发一个应用程序,它显示有关 C99 标准库中各种函数头的信息。你可以想象,其中一些标题包含相当多的功能......比我想放在主屏幕上的功能还要多。我认为更好的处理方法是为每个标题创建组(有一个摘要项目,然后是一个包含函数项目的函数组),所以它们在自己的页面上。

但是,我在使用 Microsoft 提供的模板以编程方式执行此操作时遇到了问题。

这是我为“complex.h”组提供的代码,理想情况下,它会包含一个摘要项,然后是一个名为“ComplexConstituents”的组:

var complexGroup = new SampleDataGroup("<complex.h>",
                "<complex.h>",
                "complex arithmetic",
                "Assets/LightGray.png",
                "Group Description: ");
        complexGroup.Items.Add(new SampleDataItem("Group-2-Item-1",
                "Summary",
                "summary of <complex.h>",
                "Assets/DarkGray.png",
                "Item Description: summary of <complex.h>",
                ITEM_CONTENT,
                complexGroup));
        this.AllGroups.Add(complexGroup);
        var complexConstituents = new SampleDataGroup("<complex.h> functions",
                "<complex.h> functions",
                "functions included in the <complex.h> header",
                "Assets/MediumGray.png",
                "Group description: blah");
        this.ComplexConstituents.Add(complexConstituents);

您可能已经注意到我在这里添加了第二种类型的组来补充“AllGroups”。它是“ComplexConstituents”,应该是内部包含 .这是它的构造函数,与“AllGroups”的构造函数进行比较:

    private ObservableCollection<SampleDataGroup> _allGroups = new ObservableCollection<SampleDataGroup>();
    public ObservableCollection<SampleDataGroup> AllGroups
    {
        get { return this._allGroups; }
    }
    private ObservableCollection<SampleDataGroup> _complexConstituents = new ObservableCollection<SampleDataGroup>();
    public ObservableCollection<SampleDataGroup> ComplexConstituents
    {
        get { return this._complexConstituents; }
    }

我认为这已经足够了,但无论出于何种原因,它都不是。我在这篇文章的末尾得到了错误(如图)。我需要做什么来解决这个问题?

编辑:

这是一些人要求的 GetItem 方法:

public static SampleDataItem GetItem(string uniqueId)
    {
        // Simple linear search is acceptable for small data sets
        var matches = _sampleDataSource.AllGroups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId));
        if (matches.Count() == 1) return matches.First();
        return null;
    }

【问题讨论】:

  • 显示GetItem方法,可能解析错误。
  • 已编辑以包含它,首席。
  • 我发布答案。让我知道此更改是否成功。

标签: c# windows-8 microsoft-metro


【解决方案1】:

在您的 GetItem 方法中,您必须进行更改,因为您使用 ComplexConstituents 作为数据源。

像这样编辑:

var matches = _sampleDataSource.ComplexConstituents.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId));

 var matches2 = _sampleDataSource.AllGroups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId));

        if (matches.Count() == 1) 
            return matches.First();
        else if(matches2.Count() == 1)
            return matches2.First();
        else
           return null;

【讨论】:

  • 这似乎带来了另一个问题。应用程序主页上的其他“主要”组需要 var 匹配来处理 AllGroups,而不是 ComplexConstituents。是否可以为每个组创建一个案例?
  • 我编辑了我的帖子。但在这种情况下,您需要在组中拥有不同的项目。另一种方法是实现第二种方法。
  • 不幸的是,这似乎并不能缓解问题。单击页面上的其他项目时,它不会弹出任何内容,而是停留在主页上。该组也不显示在 complex.h 类别中的其他项目下。 ://
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多