我的代码中已经有一个 ListBox,现在我添加了一个新的:
<ListBox x:Name="Diaryresult"
Foreground="Black"
Margin="19,0,0,8">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Binding {name}"
FontSize="24" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我正在使用以下代码填充此列表:
XElement diary = XElement.Parse(e.Result);
IEnumerable<XElement> diaryelements = diary.Elements("diaryelement");
List<Produkt> diaryprodukte = new List<Produkt>();
foreach (XElement diaryelement in diaryelements)
{
Produkt p = new Produkt();
p.name = diaryelement.Element("diaryshortitem").Element("description").Element("name").Value;
p.shortfacts = diaryelement.Element("diaryshortitem").Element("data").Element("kj").Value + " KJ - "
+ diaryelement.Element("diaryshortitem").Element("data").Element("kcal").Value + "kcal";
diary.Add(p);
Debug.WriteLine("Added "+p.name);
}
Diaryresult.ItemsSource = diaryprodukte;
Diaryresult.Visibility = System.Windows.Visibility.Visible;
但是,它没有出现。有人看到诀窍了吗?