title: Changing ListBox feeds into Pivot (SyndicationItem message instead of text)
body: <p>So, I found a way of creating RSS feed app for Windows Phone. It binds SyndicationFeed items into Listbox template. And it works great!
  However, I wanted to make an app, that handles a bit different. I thought, that changing Listbox template into Pivot would be quite easy. The problem is, that instead of articles I get only "System.ServiceModel.Syndication.SyndicationItem".</p>
  
  <p>I am out of ideas how to fix that, could anyone help me?</p>
  
  <p>Xaml:
      
  
  <pre><code>mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
  FontFamily="{StaticResource PhoneFontFamilyNormal}"
  FontSize="{StaticResource PhoneFontSizeNormal}"
  Foreground="{StaticResource PhoneForegroundBrush}"
  SupportedOrientations="Portrait"  Orientation="Portrait"
  shell:SystemTray.IsVisible="True"&gt;
  
  &lt;!--LayoutRoot is the root grid where all page content is placed--&gt;
  &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt;
  
      &lt;Popup Name="myPopup" IsOpen="True" Width="Auto"&gt;
          &lt;ProgressBar Height="Auto" IsIndeterminate="True"  Width="480" /&gt;
      &lt;/Popup&gt;
  
      &lt;controls:Pivot Name="FeedPivot" Loaded="loadFeed"&gt;
          &lt;controls:Pivot.Title&gt;
              &lt;TextBlock FontSize="56"&gt; Komorkomania &lt;/TextBlock&gt;
          &lt;/controls:Pivot.Title&gt;
  
          &lt;controls:Pivot.HeaderTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid&gt;
                      &lt;TextBlock&gt;test1&lt;/TextBlock&gt;
                   &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/controls:Pivot.HeaderTemplate&gt;
  
          &lt;controls:Pivot.DataContext&gt;
              &lt;DataTemplate&gt;
                  &lt;StackPanel&gt;
                      &lt;TextBlock&gt;test&lt;/TextBlock&gt;
                      &lt;!--
                      &lt;TextBlock FontWeight="Bold" FontSize="28" Name="feedTitle" TextWrapping="Wrap" Margin="12,0,0,0" HorizontalAlignment="Left" Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Title.Text, Converter={StaticResource RssTextTrimmer}}" Width="430" /&gt;
                      &lt;TextBlock Name="feedSummary" FontSize="24" TextWrapping="Wrap" Margin="12,0,0,0" Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmer}}" Width="430" /&gt;
                      &lt;TextBlock Name="feedPubDate" Foreground="{StaticResource PhoneSubtleBrush}" Margin="12,0,0,10" Text="{Binding PublishDate.DateTime}" Width="430" /&gt;
                      --&gt;
                   &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/controls:Pivot.DataContext&gt;
  
        &lt;/controls:Pivot&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Code behind:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Animation;
  using System.Windows.Shapes;
  using Microsoft.Phone.Controls;
  using System.IO;
  using System.ServiceModel.Syndication;
  using System.Xml;
  using Microsoft.Phone.Tasks;
  using Microsoft.Phone.Shell;
  using System.ComponentModel;
  using System.Windows.Controls.Primitives;
  
  namespace KomorkomaniaRss
  {
      public partial class MainPage : PhoneApplicationPage
      {
      // Constructor
      public MainPage()
      {
          InitializeComponent();
          myPopup.IsOpen = true;
      }
  
      // Co robimy jak już w końcu się ściągnie?
      private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
      {
          if (e.Error != null)
          {
              Deployment.Current.Dispatcher.BeginInvoke(() =&gt;
              {
                  MessageBox.Show(e.Error.Message);
              });
          }
          else
          {
              // Save the feed into the State property in case the application is tombstoned. 
              this.State["feed"] = e.Result;
  
              UpdateFeedList(e.Result);
              myPopup.IsOpen = false;
          }
      }
  
      // This method determines whether the user has navigated to the application after the application was tombstoned.
  
      protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
      {
          // First, check whether the feed is already saved in the page state.
          if (this.State.ContainsKey("feed"))
          {
              // Get the feed again only if the application was tombstoned, which means the ListBox will be empty.
              // This is because the OnNavigatedTo method is also called when navigating between pages in your application.
              // You would want to rebind only if your application was tombstoned and page state has been lost. 
              if (FeedPivot.Items.Count == 0)
              {
                  UpdateFeedList(State["feed"] as string);
              }
          }
      }
  
      // This method sets up the feed and binds it to our ListBox. 
      private void UpdateFeedList(string feedXML)
      {
          // Load the feed into a SyndicationFeed instance.
          StringReader stringReader = new StringReader(feedXML);
          XmlReader xmlReader = XmlReader.Create(stringReader);
          SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
  
          Deployment.Current.Dispatcher.BeginInvoke(() =&gt;
          {
              // Bind the list of SyndicationItems to our ListBox.
              FeedPivot.ItemsSource = feed.Items;
  
          });
      }
  
      public void feedLoader()
      {
          myPopup.IsOpen = true;
          WebClient webClient = new WebClient();
          webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
          webClient.DownloadStringAsync(new System.Uri("http://komorkomania.pl/feed/rss2"));
      }
  
      private void runBrowser(object sender)
      {
          ListBox listBox = sender as ListBox;
  
          if (listBox != null &amp;&amp; listBox.SelectedItem != null)
          {
              // Get the SyndicationItem that was tapped.
              SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem;
  
              // Set up the page navigation only if a link actually exists in the feed item.
              if (sItem.Links.Count &gt; 0)
              {
                  // Get the associated URI of the feed item.
                  Uri uri = sItem.Links.FirstOrDefault().Uri;
  
                  // Create a new WebBrowserTask Launcher to navigate to the feed item. 
                  // An alternative solution would be to use a WebBrowser control, but WebBrowserTask is simpler to use. 
                  WebBrowserTask webBrowserTask = new WebBrowserTask();
                  webBrowserTask.Uri = uri;
                  webBrowserTask.Show();
              }
          }
  
      }
  
      // The SelectionChanged handler for the feed items 
      private void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          runBrowser(sender);
      }
  
      private void loadFeed(object sender, RoutedEventArgs e)
      {
          feedLoader();
          if (!App.ViewModel.IsDataLoaded)
          {
              App.ViewModel.LoadData();
          }
      }
  }
  }
  </code></pre>
  
  <p>There are some "leftovers" for handling another actions. Please ignore them, I didn't get to it yet. The biggest focus is to make it show text after app is loaded.</p>