I try to implement HierarchicalDataTemplate for the self referencing table in Silverlight 4.

It shows all items in the TreeView like 1 level instead of the hierarchical view. It should be 3 levels of the items.

So I got stuck how to do it… Any clue? Thank you!
<UserControl x:Class="TreeViewCRUD.MainPage"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
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:Crud="clr-namespace:TreeViewCRUD"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid>
<sdk:TreeView Height="403" Margin="0,0,0,0" Name="TreeView1" Background="Beige" >
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Divisions}" >
<TextBlock Text="{Binding Name, Mode=OneWay}" Margin="5,0"></TextBlock>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
</Grid>
</UserControl>
and C#
void client_GetDivisionsCompleted(object sender, MyService.GetDivisionsCompletedEventArgs e)
{
var lst = e.Result;
try
{
TreeView1.DataContext = lst;
// TreeView1.ItemsSource = lst;
TreeView1.ItemsSource = lst.Where(a=>a.DivisionID != null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
}
}
I suspect that your XAML is correct(mostly) and the data is the issue. I assume
lstcontains some data likeWhen what you really need
lstto be isNow lst[0].Divisions1 would be
And finally lst[0].Divisions1[0].Divisions1 would be
Verify that the data from WCF is coming with the Navigation Properties intact. Even if
lstshows all 3 elements instead just the top level one, you should be able to filter that down client side.The last thing I noticed is that you are using
ItemsSource="{Binding Divisions}"for your binding. However, in the class diagram, the properties name isDivisions1