2012-04-21 13 views
0

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を通過するかです。例外を取得し、コンテンツを取得します。

+0

を必要とタイトルと内容を記入し、私は提案やポインタを探しています。 誰かが前にこのようなことを試したことがありますか? – Goran303

答えて

2

まず、Itemを別の場所(Page)からアクセスする場所に保存してください。例えば

SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem; 
PhoneApplicationService.Current["myItem"] = sItem; 

よりも、新しいページを作成し、詳細ページのコンストラクタで、それにNavigationService.Navigate(new Uri("/newPage.xaml"));

をナビゲートし、現在

SyndicationItem sItem = PhoneApplicationService.Current["myItem"] as SyndicationItem; 
// set Title and so on... 
+0

"目的地" の形で私のコード:(私はとNullReferenceExceptionを取得) ます。private void PhoneApplicationPage_Loaded(オブジェクト送信者、RoutedEventArgs e)の { てみ {SyndicationItem sItem = PhoneApplicationService.Current.State [ "postovi"] SyndicationItemとして; tb_Content.Text = sItem.Content.ToString(); //コンテンツのテキストブロック PageTitle.Text = sItem.Title.ToString(); //タイトルは、 の形式のページタイトルになります。 catch(例外f) { MessageBox。表示(f.Message、 "Error"、MessageBoxButton.OK); } } – Goran303

+0

'sItem'または' sItem.Content'が 'null'であることを確認してください。より単純なデータ型、 'string'のように渡して、すべてが動作することを確認してください。ここから取得する前にオブジェクトが 'State'に保存されていることを確認してください。 – Ku6opr

+0

文字列が渡されました。 – Goran303

関連する問題