我正在开发一个应用程序,它显示有关 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;
}