Quantcast
Channel: How to open an article of the RSS feed in a new form? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to open an article of the RSS feed in a new form?

$
0
0

Do you know what to add to the code to open desired article from the RSS feed. In a new form.

In a new form I should get Title and Content of the article, Image is optional

Here is my code where the list of articles is:

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);
        }
    }

I have written a code that does most of the job right:

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);
        }
    }

The content isnt recognized and I get NullReference all the time, when I linked Summary on the TextBlock the date of the article was shown fine. Also every time when I goback on list where all the articles are listed I get an Error "You can only use State between OnNavigatedTo" and "OnNavigatedFrom". When I press home button debugger shows up (app crashes).

This is what I get: A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.dll A first chance exception of type 'System.Security.SecurityException' occurred in System.Runtime.Serialization.dll A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll A first chance exception of type 'System.Security.SecurityException' occurred in System.Runtime.Serialization.dll The thread '' (0xfc2037a) has exited with code 0 (0x0). The thread '' (0xe880366) has exited with code 0 (0x0). The thread '' (0xe310372) has exited with code 0 (0x0). The thread '' (0xf970392) has exited with code 0 (0x0). The thread '' (0xe470392) has exited with code 0 (0x0).

This is the feed I am working on: http://www.zimo.co/feed/ my main problem is how to get past the nullref. exception and get the content.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images