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のSummaryをリンクしたとき、記事の日付がうまく表示されました。また、すべての記事がリストされているリストをゴブしたときに、「OnNavigatedToとOnNavigatedFromの間でのみStateを使用できます」というエラーが表示されます。ホームボタンデバッガを押すと、アプリがクラッシュします。
これは私が得るものです:「System.InvalidOperationException」種類の 最初のチャンス例外は、型「System.Security.SecurityException」の最初のチャンス例外がSystem.Runtime.Serializationで発生したMicrosoft.Phone.dll で発生しました.dll 'System.Reflection.TargetInvocationException'型の最初のチャンス例外がmscorlib.dllで発生しました 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