How to get the Sub directories also In my code. I am using Silverlight Application.Please send me the code.
XML File:
XAML Code :
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"
xmlns:ig="http://schemas.infragistics.com/xaml"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
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.Resources;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;
namespace Infragistics_SilverLight
{
public partial class TreeDemo : UserControl
{
public TreeDemo()
{
InitializeComponent();
Read();
}
public class Book
{
public string Author { get; set; }
public string Title { get; set; }
public string UnitPrice { get; set; }
public string Url { get; set; }
public decimal Price { get; set; }
public string ReleaseDate { get; set; }
public IEnumerable Chapters { get; set; }
public XNode node { get; set; }
}
public class Chapter
{
public string Title { get; set; }
public string Author { get; set; }
public string UnitPrice { get; set; }
public XNode node { get; set; }
}
private IEnumerable GetChapters(XElement parent)
{
return (from d in parent.Descendants("chapter")
select new Chapter
{
Title = d.Attribute("Title").Value,
node = d
}).ToList();
}
//private void MyTree_ActiveItemChanged_1(object sender, Infragistics.Controls.Menus.ActiveItemChangingEventArgs e)
//{
// //txtBox.Text += PrintLog(DataTreeStrings.XDT_ActiveNodeChanged);
//}
public void Read()
{
try
{
XDocument doc = XDocument.Load("Books.xml");
var dataSource = (from d in doc.Descendants("book")
where (d.Descendants("chapter") != null && d.Descendants("chapter").Count() > 0)
select new Book
{
Author = d.Attribute("Author").Value,
Title = d.Attribute("Title").Value,
UnitPrice = d.Attribute("UnitPrice").Value,
Url = d.Attribute("Url").Value,
ReleaseDate = d.Attribute("ReleaseDate").Value,
Chapters = this.GetChapters(d),
node = d
});
this.MyTree.ItemsSource = dataSource.ToList();
}
catch (Exception)
{
throw;
}
}
private void MyTree_ActiveItemChanged_2(object sender, EventArgs e)
{
}
}
}
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Gokhul VarmanPosted Aug 9, 2017, 2:30 PM