【发布时间】:2018-01-04 16:06:21
【问题描述】:
试图在列表视图中绑定一个数据子数组。 假设我有一个这种格式的 json:
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
假设这是我的模型
public class GlossDef
{
public string para { get; set; }
public List<string> GlossSeeAlso { get; set; }
}
public class GlossEntry
{
public string ID { get; set; }
public string SortAs { get; set; }
public string GlossTerm { get; set; }
public string Acronym { get; set; }
public string Abbrev { get; set; }
// ===edit=== lets assume I have GlossDef is a list.
public List<GlossDef> GlossDef { get; set; }
public string GlossSee { get; set; }
}
public class GlossList
{
public GlossEntry GlossEntry { get; set; }
}
public class GlossDiv
{
public string title { get; set; }
public GlossList GlossList { get; set; }
}
public class Glossary
{
public string title { get; set; }
public GlossDiv GlossDiv { get; set; }
}
public class RootObject
{
public Glossary glossary { get; set; }
}
让我们说这是我的 xaml:
<ListView x:Name="listview" SeparatorVisibility="None"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="20, 10">
<Label Text="{Binding Title}"/> //this works fine
<Label Text="{Binding Para}"/> //how can I do this
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
有什么方法可以在列表视图中绑定子数组吗?我尝试使用嵌套列表视图,但我的应用程序刹车,我读到嵌套列表视图通常会使我的应用程序崩溃。我正在调查this thread,这正是我的问题,他也在 SO (How To Bind the JSON Sub Array Data into Listview in xamarin.forms) 中发布,但没有收到正确的答案。任何帮助将不胜感激。谢谢你:))
【问题讨论】:
标签: c# json xamarin data-binding xamarin.forms