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 Microsoft.SharePoint.Client;
namespace SilverlightSampleWebPart
{
public partial class MainPage : UserControl
{
private ClientContext context;
private NavigationNodeCollection nav;
SiteNodes site;
public class SiteNodes
{
public string Title { get; set; }
public List<
SiteChildren
> Children { get; set; }
}
public class SiteChildren
{
public string Title { get; set; }
}
public MainPage()
{
InitializeComponent();
context = new ClientContext(ApplicationContext.Current.Url);
context.Load(context.Web);
nav = context.Web.Navigation.QuickLaunch;
context.Load(nav);
context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);
}
private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{
// This is not called on the UI thread.
Dispatcher.BeginInvoke(BindData);
}
private void BindData()
{
List<
SiteNodes
> siteColl = new List<
SiteNodes
>();
site = new SiteNodes { Title = context.Web.Title };
site.Children = new List<
SiteChildren
>();
foreach (NavigationNode nn in nav)
{
BindChilds(nn);
}
siteColl.Add(site);
treeView.ItemsSource = siteColl;
}
private void BindChilds(NavigationNode nn)
{
SiteChildren sn = new SiteChildren{ Title = nn.Title };
site.Children.Add(sn);
}
private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<
object
> e)
{
}
}
}