【发布时间】:2018-02-01 20:38:33
【问题描述】:
我在 gridview 上有一个图像绑定,下面是 XAML:
<Border x:Name="coverBox" Grid.Row="0" Margin="5,10,0,0" Width="230" Height="170" VerticalAlignment="Top" HorizontalAlignment="Left" BorderBrush="Gray" BorderThickness="1" Background="{x:Null}">
<Image x:Name="cover" Source="{Binding Thumbnail}" HorizontalAlignment="Center" Stretch="Uniform" AutomationProperties.Name="{Binding Title}" Width="230" Height="170"/>
</Border>
代码:
string urlPath1 = "http://..../API/sekolah";
var httpClient1 = new HttpClient(new HttpClientHandler());
var values1 = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("api_key", "...."),
new KeyValuePair<string, string>("limit", limit++.ToString()),
new KeyValuePair<string, string>("hal", noHal++.ToString())
};
var response1 = await httpClient1.PostAsync(urlPath1, new FormUrlEncodedContent(values1));
response1.EnsureSuccessStatusCode();
if (!response1.IsSuccessStatusCode)
{
busyIndicator.IsActive = false;
RequestException();
}
string jsonText1 = await response1.Content.ReadAsStringAsync();
JsonObject jsonObject1 = JsonObject.Parse(jsonText1);
JsonArray jsonData1 = jsonObject1["data"].GetArray();
foreach (JsonValue groupValue1 in jsonData1)
{
JsonObject groupObject2 = groupValue1.GetObject();
string thumbnail = groupObject2.ContainsKey("thumbnail") && groupObject2["thumbnail"] != null ? groupObject2["thumbnail"].GetString() : string.Empty;
ListingClass file1 = new ListingClass();
file1.Thumbnail = thumbnail;
listingDatasourceDetail.Add(file1);
}
listingGridView.ItemsSource = listingDatasourceDetail;
我想在加载的同时从 JSON 中获取图像数据,然后首先显示 paceholder images/SEKOLAH-place-holder-600.png
如何在加载时添加占位符?
【问题讨论】:
标签: c# json image gridview uwp