Reputation: 1620
I am getting data via a REST web service and need to show the data in a list view. 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:
<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:
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
Upvotes: 0
Views: 893
Reputation: 89285
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. I guess you want to set ItemsSource
to dealList
which type is List<Data>
:
ItemData.ItemsSource = dealList;
Upvotes: 1