[英]Binding Json data to TextBlock in windows phone 8.1
I am getting data via a REST web service and need to show the data in a list view. 我正在通过REST Web服务获取数据,并且需要在列表视图中显示数据。 My problem is that I am not being able to bind the data.
我的问题是我无法绑定数据。 The error I am getting is - Error:
我收到的错误是-错误:
Error: BindingExpression path error: 'id' property not found on 'Windows.Foundation.IReference`1<String>'. BindingExpression: Path='id' DataItem='Windows.Foundation.IReference`1<String>'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Text' (type 'String')
Model Code : 型号代码:
public class Deal
{
public String id { get; set; }
public string businessName { get; set; }
}
XAML Code: XAML代码:
<ListView Name="ItemData"
HorizontalAlignment="Left"
Height="640"
VerticalAlignment="Top"
Width="396">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Width="100" FontSize="22" Text="Deal ID:"/>
<TextBlock Width="100" FontSize="22" Text="{Binding id}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
CS Function: CS功能:
private async void MakeListData()
{
HttpConnection httpConnect = new HttpConnection();
String result = await httpConnect.ReadDataFromWeb();
DealDataModel rootObject = JsonConvert.DeserializeObject<DealDataModel>(result);
List<Deal> dealList = rootObject.deals;
List<string> idList = new List<string>();
for (int i = 0; i < dealList.LongCount(); i++)
{
idList.Add(dealList[i].id);
}
ItemData.ItemsSource = idList;
}
Would appreciate if someone can help me overcome this problem. 如果有人可以帮助我克服这个问题,将不胜感激。 Thanks
谢谢
Your code use List<string>
for the ItemsSource
and string
doesn't have property id
, that's explain why binding engine failed to find id
property. 您的代码将
List<string>
用于ItemsSource
并且string
没有属性id
,这说明了绑定引擎为何找不到id
属性的原因。 I guess you want to set ItemsSource
to dealList
which type is List<Data>
: 我猜您想将
ItemsSource
设置为dealList
,其类型为List<Data>
:
ItemData.ItemsSource = dealList;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.