Feed news head line to DataGrid : DataGrid « UI Controls « Silverlight






Feed news head line to DataGrid

   


<UserControl x:Class='SilverlightApplication3.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'
    xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
    <Grid x:Name="LayoutRoot" Background="White">
        <my:DataGrid x:Name="GrdHeadline" AutoGenerateColumns="True"></my:DataGrid>
    </Grid>
</UserControl>


//File: Page.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
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 System.Net;
using System.Xml.Linq;

namespace SilverlightApplication3
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            
            WebClient client = new WebClient(); 
            Uri uri = new Uri("http://feeds.reuters.com/reuters/topNews?format=xml");
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            client.DownloadStringAsync(uri);
            
        }
        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XDocument xmlHeadlines = XDocument.Parse(e.Result);
            var headlines = from story in xmlHeadlines.Descendants("item")select new NewsHeadLine{
                                strHead = (string)story.Element("title"),
                                strLine = (string)story.Element("link")
                            };
            GrdHeadline.ItemsSource = headlines;
        }
    }
    public class NewsHeadLine
    {
        public string strHead { get; set; }
        public string strLine { get; set; }
    }
    
}

   
    
    
  








Related examples in the same category

1.Implementing a DataGrid ControlImplementing a DataGrid Control
2.A basic DataGrid.A basic DataGrid.
3.Manually adding columns to a DataGridManually adding columns to a DataGrid
4.Empowering your users to sort the columns of a DataGridEmpowering your users to sort the columns of a DataGrid
5.Fill RSS feed to DataGridFill RSS feed to DataGrid