我正在从MSDN开始学习有关城域应用的教程。
namespace MetroTutorial
{
partial class MainPage
{
public MainPage()
{
InitializeComponent();
GetFeedAsync("http://windowsteamblog.com/windows/b/developers/atom.aspx");
}
private async Task GetFeedAsync(string feedUriString)
{
// using Windows.Web.Syndication;
SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri(feedUriString);
try
{
SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
FeedData feedData = new FeedData();
feedData.Title = feed.Title.Text;
foreach (SyndicationItem item in feed.Items)
{
FeedItem feedItem = new FeedItem();
feedItem.Title = item.Title.Text;
feedItem.PubDate = item.PublishedDate.DateTime;
feedItem.Author = item.Authors[0].Name.ToString();
if (feed.SourceFormat == SyndicationFormat.Atom10)
{
feedItem.Content = item.Content.Text;
}
else if (feed.SourceFormat == SyndicationFormat.Rss20)
{
feedItem.Content = item.Summary.Text;
}
feedData.Items.Add(feedItem);
}
this.DataContext = feedData;
ItemListView.SelectedIndex = 0;
}
catch (Exception ex)
{
// Log Error.
ex.ToString();
}
}
}
public class FeedData
{
public string Title
{
get;
set;
}
private ObservableCollection<FeedItem> _Items = new ObservableCollection<FeedItem>();
public ObservableCollection<FeedItem> Items
{
get
{
return this._Items;
}
}
}
public class FeedItem
{
public string Title { get; set; }
public string Content { get; set; }
public string Author { get; set; }
public DateTime PubDate { get; set; }
}
}
但我无法使它工作,当我运行它时,它只是用一个时钟打开窗口就是这样。
我是否需要在XAML中将某些内容设置为ListView,如果是,究竟是什么?
答案 0 :(得分:1)
第一个问题是我的ListView不可见,我不得不放大添加List时出现的那个方块。
然后我必须设置:
ItemsSource="{Binding Items}"
DisplayMemberPath="Title"
多数民众赞成。