alert('Oh shit !!!! Javascript is disabled!!!! ');


Blog Archive

How to Add XML File in Your Silverlight Project

How to Add XML File in Your Silverlight Project

Add Xml File named as Employee.xml and write the code given below

.XAML Code: Write this code in MainPage.xaml

<UserControl x:Class="SilverlightApplication14.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:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
   <ListBox x:Name="EmployeeList" Width="400" Height="200" 
SelectionChanged="EmployeeList_SelectionChanged" />
    </Grid>
</UserControl>

.CS Code: Write this code in MainPage.xaml.cs page

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 System.Xml;

namespace SilverlightApplication14
{
   public partial class MainPage : UserControl
    {
       public MainPage()
        {
        InitializeComponent();
        PopulateEmployeeList();
        }
        private void PopulateEmployeeList()
        {
            XmlReader reader = XmlReader.Create("Employee.xml");
            reader.MoveToContent();
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name
==
"customer") { EmployeeList.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("last") + ", " + reader.GetAttribute("first") + " (" + reader.ReadInnerXml() + ")" }); } if (reader.NodeType == XmlNodeType.EndElement && reader.Name ==
"Employee") { break; } } reader.Close(); } } }

Run the Silverlight Application