简体   繁体   中英

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. 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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM