【发布时间】:2017-08-29 03:30:41
【问题描述】:
我想使用下图在 gridview 中显示数据的“评级”:
例如评分值为5,会显示如下:
如果评分为3,则显示如下:
如果评分为0,则显示如下:
代码:
try
{
loading.Visibility = Visibility.Visible;
string urlPath1 = "http://.../results.json?module=listing&page=1&token=3f63-dc43-c8d5-eb45-8cbf-b72d-9d98-800f";
var httpClient1 = new HttpClient(new HttpClientHandler());
var values1 = new List<KeyValuePair<string, string>>
{
};
HttpResponseMessage response1 = await httpClient1.GetAsync(urlPath1);
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 title = groupObject2["title"].GetString();
double rating = groupObject2["rating"].GetNumber();
ListingClass file1 = new ListingClass();
file.Title = title;
file1.Rating = Convert.ToInt32(rating);
listingDatasource.Add(file1);
}
itemGridView.ItemsSource = listingDatasource;
busyIndicator.IsActive = false;
}
catch (HttpRequestException ex)
{
busyIndicator.IsActive = false;
RequestException();
}
如何使用图片显示评分?
注意: 评分最大值为5
【问题讨论】:
-
您是否有 5 张独特的评级图像或一张精灵图像?
-
@Sameer 是的,我使用上面的图片。对于使用星星的全彩色图像的评分值为 1,而使用仅边框的星星图像评分为 0。
-
@fnostro 我想使用上图更改 json 值的评级。
-
@Rose - 我的错误,抱歉。
标签: c# json image gridview uwp