我遇到了一个问题,我在 App.cs 上创建了一个类:
public class Article
{
public string Text { get; set; }
public int Id { get; set; }
public long Date { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string ImageURL { get; set; }
}
还有一个公共变量:
public Article ToArticlePage { get; set; }
在 NewsPage 上,我有相同的课程文章:
public class Article
{
[JsonProperty("text")]
public string Text { get; set; }
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("date")]
public long Date { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("author")]
public string Author { get; set; }
[JsonProperty("imageURL")]
public string ImageURL { get; set; }
}
然后我正在尝试这样做:
在选择更改时,我正在解析文章 ID,并在文章列表 ( NewsList ) 中找到它。并将其提供给全局变量 ToArticlePage。
private void NewsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NLBI = (NewsListBoxItem)NewsListBox.SelectedItem;
Predicate <Article> articleFinder = (Article p) => { return p.Id == int.Parse(NLBI.id.Text); };
(App.Current as App).ToArticlePage = NewsList.Result.Articles.Find(articleFinder);
}
错误:
Error 7 Cannot convert type 'WP8Release2.NotAuthorizedPages.HomePage.Article' to 'WP8Release2.Article' C:\Users\4\Documents\Visual Studio 2012\Projects\WP8Release2\WP8Release2\NotAuthorizedPages\HomePage.xaml.cs 348 50 WP8Release2
Error 12 Cannot implicitly convert type 'WP8Release2.NotAuthorizedPages.HomePage.Article' to 'WP8Release2.Article' C:\Users\4\Documents\Visual Studio 2012\Projects\WP8Release2\WP8Release2\NotAuthorizedPages\HomePage.xaml.cs 348 50 WP8Release2