【发布时间】:2016-08-11 01:22:57
【问题描述】:
我正在我的项目中尝试 CarouselView。但是当我运行我的项目时,我得到了这个错误。
这是我的 xaml 代码;
<?xml version="1.0" encoding="UTF-8"?>
<base:HotelDetailPageXaml
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinCRM.Pages.Hotels.HotelDetailPage"
xmlns:statics="clr-namespace:XamarinCRM.Statics"
xmlns:base="clr-namespace:XamarinCRM.Pages.Hotels"
xmlns:hotelViews="clr-namespace:XamarinCRM.Views.Hotels"
xmlns:i18n="clr-namespace:XamarinCRM.Localization"
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
Title="{Binding Hotel.Name}">
<base:HotelDetailPageXaml.Content>
<StackLayout Spacing="0">
<cv:CarouselView ItemsSource="{Binding Hotel.HotelImages}">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout HeightRequest="200">
<Image HeightRequest="200" Aspect="AspectFill" Source="{Binding FullPath}"/>
</StackLayout>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
</StackLayout>
</base:HotelDetailPageXaml.Content>
</base:HotelDetailPageXaml>
这里是我调用的json服务;
public async Task<IEnumerable<HotelModel>> GetHotelsAsync(bool includeLeads = false)
{
string path = "my service url";
HttpClient Client = new HttpClient();
var task = await Client.GetAsync(path);
var jsonString = await task.Content.ReadAsStringAsync();
List<HotelModel> hotelList = new List<HotelModel>();
List<HotelImageModel> hotelImageList = new List<HotelImageModel>();
dynamic json = JsonConvert.DeserializeObject(jsonString);
for (int j = 0; j < 10; j++)
{
HotelImageModel hotelImage = new HotelImageModel();
hotelImage.FullPath = json["data"][i]["HotelImages"][j]["FullPath"].Value;
hotel.HotelImages.Add(hotelImage);
}
}
i 是 for 的酒店索引号,j 是酒店的图像索引号
【问题讨论】:
-
看起来你有一个例外。 :-) 请发布失败的代码和完整的堆栈跟踪。避免将文字作为照片发布。
-
我已经添加了更多细节......请看这个。
标签: xamarin xamarin.ios xamarin.forms