我正在尝试在我的搜索中找到我的变量接收值,但是当我去检查变量是否为空时,值正在传递,并且在我的列表中生成相同的信息
命令列表提要
private Command loadItemsCommand;
public Command LoadItemsCommand
{
get { return loadItemsCommand ?? (loadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand())); }
}
private async Task ExecuteLoadItemsCommand()
{
if (IsBusy)
return;
IsBusy = true;
var error = false;
try
{
var responseString = string.Empty;
using (var httpClient = new HttpClient())
{
var feed = "url feed";
responseString = await httpClient.GetStringAsync(feed);
}
var items = await ParseFeed(responseString);
foreach (var item in items)
{
FeedItems.Add(item);
}
}
catch
{
error = true;
}
if (error)
{
var page = new ContentPage();
await page.DisplayAlert("Error", "Unable to load blog.", "OK");
}
IsBusy = false;
}
private async Task<List<FeedItem>> ParseFeed(string rss)
{
return await Task.Run(() =>
{
var xdoc = XDocument.Parse(rss);
var id = 0;
return (from item in xdoc.Descendants("item")
let enclosure = item.Element("enclosure")
where enclosure != null
select new FeedItem
{
Title = (string)item.Element("title"),
Description = (string)item.Element("description"),
Link = (string)item.Element("link"),
PublishDate = DateTime.Parse((string)item.Element("pubDate")).ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss"),
Category = (string)item.Element("category"),
Mp3Url = (string)enclosure.Attribute("url"),
Image = (string)enclosure.Attribute("url"),
Color_category = "#" + Convert.ToString(int.Parse((string)item.Element("color")), 16).PadLeft(6, '0'),
Id = id++
}).Skip(0).Take(1).ToList();
});
}
上课
public class FeedItem : INotifyPropertyChanged
{
public static string title;
public string Title
{
get { return title; }
set { title = value; }
}
}
load&#34; FeedItem m = new FeedItem(); teste.Text = m.Title; &#34;什么都没有回到我身上
public feed()
{
InitializeComponent();
BindingContext = new BlogFeedViewModel();
***FeedItem m = new FeedItem();
teste.Text = m.Title;***
listView.ItemTapped += (sender, args) =>
{
if (listView.SelectedItem == null)
return;
this.Navigation.PushAsync(new PodcastPlaybackPage(listView.SelectedItem as FeedItem));
listView.SelectedItem = null;
};
}