Hi there,
In WPF in want to bind the List to the treeview, the first level is working, but how to get the next level.
What am i doing wrong?
Regards,
Edwin
code behind
using System; using System.Collections.Generic; using System.Windows; using Microsoft.SharePoint.Client; using System.ComponentModel; using System.Linq; using Microsoft.SharePoint.Linq; namespace SharePoint2013 { /// <summary> /// Interaction logic for SP_List_Treeview.xaml /// </summary> public partial class SP_List_Treeview : Window, INotifyPropertyChanged { public SP_List_Treeview() { InitializeComponent(); DataContext = this; _ctx = new ClientContext("http://server:15757/"); _ctx.AuthenticationMode = ClientAuthenticationMode.Default; } ClientContext _ctx; IEnumerable<List> _lists; public IEnumerable<List> lists { get { return _lists; } set { if (_lists == value) return; _lists = value; OnPropertyChanged("lists"); } } public void shardedDoc() { // Standard windows authentication _ctx.AuthenticationMode = ClientAuthenticationMode.Default; ListCollection tlists = _ctx.Web.Lists; _ctx.Load(tlists); IEnumerable<List> listsCollection = _ctx.LoadQuery( tlists.Include(l => l.Title, l => l.Id, l => l.RootFolder.Folders.Include( Folder => Folder.Name)) .Where(list => !list.Hidden && list.BaseType == BaseType.DocumentLibrary)); _ctx.ExecuteQuery(); if (_ctx.HasPendingRequest) { MessageBox.Show("Pending: " + _ctx.HasPendingRequest.ToString()); return; } lists = listsCollection; } #region INotifyPropertyChanged Members [field: NonSerialized] public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) { var handler = this.PropertyChanged; if (handler != null) { handler(this, e); } } protected virtual void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } #endregion // INotifyPropertyChanged Members private void Button_Click(object sender, RoutedEventArgs e) { shardedDoc(); } } }Xaml
<Window x:Class="SharePoint2013.SP_List_Treeview" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:spc="clr-namespace:Microsoft.SharePoint.Client;assembly=Microsoft.SharePoint.Client" xmlns:local="clr-namespace:SharePoint2013" Title="SP_List_Treeview" Height="300" Width="300"><StackPanel><Button Click="Button_Click" Content="Load"/><TreeView ItemsSource="{Binding Path=lists}"><TreeView.Resources><HierarchicalDataTemplate DataType="{x:Type spc:List}" ><TextBox Text="{Binding Title}" /></HierarchicalDataTemplate><HierarchicalDataTemplate DataType="{x:Type spc:FolderCollection}" ItemsSource="{Binding Path=RootFolder.Folders}"><TextBox Text="a{Binding Path=Name}" /></HierarchicalDataTemplate></TreeView.Resources></TreeView></StackPanel></Window>