private void ParseNews() { if (newsList == null) return; if (newsList.Count <= 0) return; foreach (Dictionary<string, object> pair in newsList) { NewsItem item = new NewsItem(); item.Margin = new System.Windows.Thickness(0, 5, 0, 5); foreach (KeyValuePair<string, object> kvPair in pair) { if (kvPair.Key == "title") { item.NewsTitle.Content = kvPair.Value; } if (kvPair.Key == "description" || kvPair.Key == "promoText") { item.DescriptionLabel.Text = (string)kvPair.Value; } if (kvPair.Key == "thumbUrl") { BitmapImage promoImage = new BitmapImage(); promoImage.BeginInit(); //Download image promoImage.UriSource = new Uri((string)kvPair.Value, UriKind.RelativeOrAbsolute); promoImage.CacheOption = BitmapCacheOption.OnLoad; promoImage.EndInit(); item.PromoImage.Source = promoImage; } if (kvPair.Key == "linkUrl") { item.Tag = (string)kvPair.Value; } } NewsItemListView.Items.Add(item); } }
private void ParseNews(BaseRegion region) { if (NewsList == null) return; if (NewsList.Count <= 0) return; string imageUri = string.Empty; foreach (Dictionary<string, object> pair in NewsList) { var item = new NewsItem { Margin = new Thickness(0, 5, 0, 5) }; foreach (var kvPair in pair) { if (kvPair.Key == "title") item.NewsTitle.Content = kvPair.Value; if (kvPair.Key == "description") { if ((string)kvPair.Value == string.Empty) continue; imageUri = ((string)kvPair.Value).Substring( ((string)kvPair.Value).IndexOf("src", StringComparison.Ordinal) + 6); if (imageUri.IndexOf("?itok", StringComparison.Ordinal) > 0) imageUri = imageUri.Remove(imageUri.IndexOf("?itok", StringComparison.Ordinal)); string noHtml = Regex.Replace(((string)kvPair.Value), @"<[^>]+>| ", "").Trim(); string noHtmlNormalised = Regex.Replace(noHtml, @"\s{2,}", " "); string noXmlAmpersands = Regex.Replace(noHtmlNormalised, @"&", "&"); item.DescriptionLabel.Text = noXmlAmpersands; } if (kvPair.Key == "link") item.Tag = kvPair.Value; // Image if (!string.IsNullOrEmpty(imageUri)) { var promoImage = new BitmapImage(new System.Uri("http://" + region.RegionName + ".leagueoflegends.com/" + imageUri, UriKind.Absolute)); item.PromoImage.Stretch = Stretch.Fill; item.PromoImage.Source = promoImage; } } NewsItemListView.Items.Add(item); } }