예제 #1
0
        private void XMLHasFinished(IAsyncResult theResult)
        {
            RefreshNewsDelegate del      = (RefreshNewsDelegate)((AsyncResult)theResult).AsyncDelegate;
            List <RssItem>      lstItems = del.EndInvoke(theResult);

            if (lstItems.Count > 0)
            {
                theItem = lstItems.First();
            }

            this.Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate()
            {
                if (theItem != null)
                {
                    blogText.ClearValue(FlowDocumentReader.DocumentProperty);
                    try
                    {
                        FlowDocument theDocument = XamlReader.Load(new XmlTextReader(new StringReader(theItem.Description))) as FlowDocument;
                        theDocument.Background   = App.Current.Resources["LightAreaFill"] as RadialGradientBrush;
                        ParseLinks(theDocument);

                        //insert the date and the title
                        Paragraph pgDateAndTitle  = new Paragraph();
                        pgDateAndTitle.FontFamily = App.Current.Resources["FontFamily"] as FontFamily;
                        pgDateAndTitle.FontWeight = FontWeights.Bold;
                        pgDateAndTitle.FontSize   = 20;
                        pgDateAndTitle.Inlines.Add(new Run(theItem.Title));
                        pgDateAndTitle.Inlines.Add(new LineBreak());
                        pgDateAndTitle.Inlines.Add(new Run(theItem.Published.ToString("yyyy-MM-dd HH:mm:ss")));
                        theDocument.Blocks.InsertBefore(theDocument.Blocks.FirstBlock, pgDateAndTitle);

                        blogText.Document = theDocument;

                        btnFullArticle.IsEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        Paragraph myErrorParagraph  = new Paragraph();
                        myErrorParagraph.FontSize   = 18;
                        myErrorParagraph.FontFamily = App.Current.Resources["FontFamily"] as FontFamily;
                        myErrorParagraph.Inlines.Add(new Run(myVariables.UnableToDisplayRSS));
                        myErrorParagraph.Inlines.Add(new LineBreak());
                        myErrorParagraph.Inlines.Add(new Run(ex.Message));
                        FlowDocument myErrorDocument = new FlowDocument();
                        myErrorDocument.Background   = App.Current.Resources["LightAreaFill"] as RadialGradientBrush;
                        myErrorDocument.Blocks.Add(myErrorParagraph);
                        blogText.Document = myErrorDocument;
                    }
                }
            }), System.Windows.Threading.DispatcherPriority.Normal);
        }
예제 #2
0
        private void XMLHasFinished(IAsyncResult theResult)
        {
            RefreshNewsDelegate del      = (RefreshNewsDelegate)((AsyncResult)theResult).AsyncDelegate;
            List <RssItem>      lstItems = del.EndInvoke(theResult);

            this.Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate()
            {
                txtStatus.Text           = myVariables.Loaded + " " + lstItems.Count.ToString(CultureInfo.InvariantCulture) + " " + myVariables.Items;
                lstNewsItems.ItemsSource = lstItems;

                //select the first item in the list box
                if (lstItems.Count > 0)
                {
                    lstNewsItems.SelectedIndex = 0;
                }
            }), System.Windows.Threading.DispatcherPriority.Normal);
        }