2016-06-09 64 views
0

我遇到了绑定我从某个网站收到的对象的问题,我创建了需要的必要模型并已验证信息是正确的,因此我知道我正在获取我的信息,问题在于我正在尝试使用某些信息创建网格,但我无法使用绑定功能处理它,似乎没有显示任何内容。 上下文:我正在使用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); 
    } 

//问题,我需要获得第二和第三级信息,而不是所有的信息该代码是在这里,但我认为它很容易理解,这是我创建

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; } 
    } 
的validtemplate机能的研究中

并在这里是信息的一个简单的例子收到

{ 
"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 

现在我知道,这是从列表视图的响应,我已经创建,但如何我可以显示我制作的绑定标签,用于显示该列表中其他层的信息: 大多数示例都是第1层json列表,因此如何获取其他层的信息

我在做什么错了? 谢谢你在高级:)

回答

0

目前,我不认为窗体支持结合变量与固定文本的绑定。

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"); 
+0

感谢杰森的快速反应,但它似乎仍然没有工作,是否有另一种解决方案,而不是使用绑定 –