问题描述
我有一个 API 可以在 .xaml 文件上显示气象数据,如下所示:
<Label Text="{Binding Coord.Lon}"
Style="{StaticResource labelResultStyle}"
TextColor="White"
FontAttributes="Bold"
Grid.Row="2"
Grid.Column="0"
HorizontalOptions="CenterandExpand"/>
对于第二个 API,我尝试绑定数据:
<Label Text="{Binding weatherForecast.MaxTemp}"
Style="{StaticResource labelResultStyle}"
FontAttributes="Bold"
HorizontalOptions="CenterandExpand"
HorizontalTextAlignment="Start"
TextColor="White"/>
显示器上没有结果。
我的第二个 Json 对象看起来像:
解决方法
weatherForecast
是一个对象的集合,因此您必须指定要使用集合的哪个元素
Text="{Binding weatherForecast[0].MaxTemp}"