Syndication.cs
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Windows.Web.Syndication;
namespace uchukamen
{
public class ObservableSyndicationCollection : ObservableCollection<SyndicationItem>
{
public async Task Get(string urlStr)
{
SyndicationClient client = new SyndicationClient();
client.BypassCacheOnRetrieve = true;
// Although most HTTP servers do not require User-Agent header, others will reject the request or return
// a different response if this header is missing. Use SetRequestHeader() to add custom headers.
client.SetRequestHeader(“User-Agent”, “Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)”);
Uri uri = new Uri(urlStr);
SyndicationFeed currentFeed = await client.RetrieveFeedAsync(uri);
foreach (SyndicationItem item in currentFeed.Items)
{
this.Add(item);
}
}
}
}
C# でバインド
uchukamen.ObservableSyndicationCollection synd = new uchukamen.ObservableSyndicationCollection();
await synd.Get(“…”);
this.itemGridView.ItemsSource = synd;
コメントを残す