您是否知道要添加到代碼中以便從RSS提要中打開所需的文章?以新的形式。如何以新形式打開RSS提要的文章?
一種新的形式,我應該得到的標題和文章的內容,圖像是可選
這裏是我的代碼,其中的文章列表:
private void ls_text_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem;
if (sItem.Links.Count > 0)
{
if (listBox != null && listBox.SelectedItem != null)
{
SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem;
PhoneApplicationService.Current.State["myItem"] = sItem;
NavigationService.Navigate(new Uri("/Clanak.xaml",UriKind.Relative));// leads to article form
}
}
}
catch (Exception f)
{
MessageBox.Show(f.Message, "", MessageBoxButton.OK);
}
}
我已經寫了代碼的大部分工作權利:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
try
{
SyndicationItem sItem = PhoneApplicationService.Current.State["myItem"] as SyndicationItem;
PageTitle.Text = sItem.Title.Text; //Title would go in the pagetitle of the form , Title shows fine
PageTitle.FontSize = 40;
//tb_Content.Text = sItem.Summary.Text; //all goes fine
foreach (SyndicationItem item in sItem.SourceFeed.Items)
{
foreach (SyndicationElementExtension ext in item.ElementExtensions)
{
if (ext.GetObject<XElement>().Name.LocalName == "encoded")
tb_Content.Text = ext.GetObject<XElement>().Value; //textblock for content, throws NullReferenceException
}
}
}
catch (Exception f)
{
MessageBox.Show(f.Message, "Error clanak", MessageBoxButton.OK);
}
}
內容無法識別,我得到NullReferen一直以來,當我在TextBlock上鍊接摘要時,文章的日期顯示正常。同樣每當我在列表中列出所有文章的列表時,我都會收到錯誤「您只能在OnNavigatedTo之間使用狀態」和「OnNavigatedFrom」。當我按Home按鈕調試器顯示(應用程序崩潰)。
這就是我得到: 「System.InvalidOperationException」類型的第一次機會異常出現在Microsoft.Phone.dll 類型「System.Security.SecurityException」的第一次機會異常出現在System.Runtime.Serialization .dll mscorlib.dll中發生類型'System.Reflection.TargetInvocationException'的第一次機會異常 System.Runtime.Serialization.dll中發生類型'System.Security.SecurityException'的第一次機會異常 線程''( 0xfc2037a)已退出代碼0(0x0)。 線程''(0xe880366)已退出,代碼爲0(0x0)。 線程''(0xe310372)已退出,代碼爲0(0x0)。 線程''(0xf970392)已退出,代碼爲0(0x0)。 線程''(0xe470392)已退出,代碼爲0(0x0)。
這是我工作的飼料:http://www.zimo.co/feed/ 我的主要問題是如何通過nullref。例外並獲取內容。
目前我填寫標題和內容我正在尋找建議或指針。 也許有人嘗試過這樣的事情? – Goran303 2012-04-21 13:05:51