I've seen several posts with similar problems and I've already tried to follow them all. Now finally I get all data on screen, but not the way I want it to be. But let's get started.
I have a ViewModel which provides the data like this:
/// <summary>
/// Returns a collection of all the ContinentListViewModel objects
/// </summary>
public static IList<Object> Items
{
get
{
IList<object> childNodes = new List<object>();
foreach (ContinentViewModel continent in _instance)
{
childNodes.Add(continent);
foreach (CountryViewModel country in continent.CountrytList)
{
childNodes.Add(country);
foreach (BusinessunitViewModel bu in country.BusinessunitList)
{
childNodes.Add(bu);
}
}
}
return childNodes;
}
}
This is my xaml-TreeView-code:
<TreeView Name="tvwBuList" ItemsSource="{Binding BusinessunitList.Items}" HorizontalAlignment="Left" VerticalAlignment="Top" MinHeight="230" MinWidth="265" MaxHeight="230" MaxWidth="265">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:ContinentViewModel}" ItemsSource="{Binding}">
<TextBlock Text="{Binding Path=ContinentCode}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:CountryViewModel}" ItemsSource="{Binding}">
<TextBlock Text="{Binding Path=CountryCode}" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:BusinessunitViewModel}">
<RadioButton GroupName="BUGroup" Content="{Binding Path=BuCode}" />
</DataTemplate>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<!--Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/-->
<Setter Property="IsExpanded" Value="True"/>
<Setter Property="Foreground" Value="Yellow"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
And this is what the output looks like:
http://imgh.us/bu_treeview.jpg
What I want to have is a complete structure like this:
+ AP
|--+ AU
O-- 164
|--+ CN
O-- 258
O-- 277
...
So what am I missing here? Help appreciated, thank you!