我在绑定从某个网站收到的对象时遇到问题,我创建了所需的必要模型并验证了信息是否正确所以我知道我收到了我的信息,问题是我正在尝试使用某些信息创建一个网格,我无法使用绑定功能处理它,似乎没有显示任何内容 上下文:我正在使用Xamarin制作移动应用程序,我也使用REST来接收某些信息
Transactions.TransactionList transactionmade = JsonConvert.DeserializeObject<Transactions.TransactionList>(result);
//用来接收信息没问题
_listView = new ListView
{
HasUnevenRows = true,
Margin = 10,
SeparatorColor = Color.Teal
};
_listView.ItemsSource = transactionmade.transactions;
_listView.ItemTemplate = validDataTemplate;
如果我做一个简单的foreach也没问题,它显示了我需要的信息
foreach (var item in transactionmade.transactions)
{
Debug.WriteLine("id=={0} .. holder=={1} .. value=={2}",
item.id, item.counterparty.holder.name, item.details.value.amount);
}
//在我需要访问第二级和第三级信息的绑定中的问题,并非所有代码都在这里,但我认为很容易理解这是在我创建的validtemplate函数内部
idLabelholder.SetBinding(Label.TextProperty, "account: {id}");
dateofCompletionLabel.SetBinding(Label.TextProperty, "details: {completed };
amountLabel.SetBinding(Label.TextProperty, "details: {value: {amount }}");
balanceLabel.SetBinding(Label.TextProperty, "details: {new_balance: {amount }}");
这是使用的模型
public class Holder
{
public string name { get; set; }
public bool is_alias { get; set; }
}
public class Bank
{
public string national_identifier { get; set; }
public string name { get; set; }
}
public class Account
{
public string id { get; set; }
public List<Holder> holders { get; set; }
public string number { get; set; }
public object kind { get; set; }
public object IBAN { get; set; }
public object swift_bic { get; set; }
public Bank bank { get; set; }
}
public class Holder2
{
public string name { get; set; }
}
public class Bank2
{
public string national_identifier { get; set; }
public string name { get; set; }
}
public class Counterparty
{
public string id { get; set; }
public Holder2 holder { get; set; }
public string number { get; set; }
public object kind { get; set; }
public object IBAN { get; set; }
public object swift_bic { get; set; }
public Bank2 bank { get; set; }
}
public class NewBalance
{
public string currency { get; set; }
public string amount { get; set; }
}
public class Value
{
public string currency { get; set; }
public string amount { get; set; }
}
public class Details
{
public string type { get; set; }
public string description { get; set; }
public string posted { get; set; }
public string completed { get; set; }
public NewBalance new_balance { get; set; }
public Value value { get; set; }
}
public class Transaction
{
public string id { get; set; }
public Account account { get; set; }
public Counterparty counterparty { get; set; }
public Details details { get; set; }
}
public class TransactionList
{
public List<Transaction> transactions { get; set; }
}
以及此处是收到的信息的简单示例
{
"transactions": [
{
"id": "065bf1e2-c39c-49b9-98ca-2604db647284",
"account": {
"id": "somebodymillionaire",
"holders": [
{
"name": "somebody1",
"is_alias": false
}
],
"number": "8585757136",
"kind": null,
"IBAN": null,
"swift_bic": null,
"bank": {
"national_identifier": "rbs",
"name": "The Royal Bank of Scotland"
}
},
"counterparty": {
"id": "f39f20a3-15ff-475e-b654-d377df58ee5d",
"holder": {
"name": "somebodycounter"
},
"number": "8964202115",
"kind": null,
"IBAN": null,
"swift_bic": null,
"bank": {
"national_identifier": "rbs",
"name": "The Royal Bank of Scotland"
}
},
"details": {
"type": "sandbox-payment",
"description": "im a millionaire",
"posted": "2016-06-07T20:36:40Z",
"completed": "2016-06-07T20:36:40Z",
"new_balance": {
"currency": "EUR",
"amount": "9449.47"
},
"value": {
"currency": "EUR",
"amount": "-550.53"
}
}
}]}
显示的信息是
App.Models.Transactions+Transaction
现在我知道这是我创建的listview的响应,但是如何显示我所做的绑定标签,以显示该列表中其他层的信息 大多数示例都是第1层json列表,所以如何获取其他层的信息
我做错了什么? 谢谢高级:)
答案 0 :(得分:0)
目前,我不相信Forms支持将变量与固定文本组合在一起的绑定。
idLabelholder.SetBinding(Label.TextProperty, "id");
dateofCompletionLabel.SetBinding(Label.TextProperty, "details.completed");
amountLabel.SetBinding(Label.TextProperty, "details.value.amount");
balanceLabel.SetBinding(Label.TextProperty, "details.new_balance.amount");