Hierarchical Views and other confusing thingies

I don’t know about you, but hierarchical views are confusing at best.  Let’s take an example:

Your boss is being their usual Monday morning attitude, expecting you to do work and all of that.  So they ask you to create a Windows Presentation Foundation (WPF) application.

As a manager they want to see how their team is doing against other teams, so you have created a a “Managers” class that contains a collection of Manager objects.

Within your class the Manager object contains a collection named TeamMembers that contains TeamMember objects. The TeamMember class has a Name property and a Sales property.

In your  bag of tricks  you have the following XAML, and you know that adding a Gird.Resource will do the trick.  If you get this done quickly you can go back to studying for the evil exam your manager has ordered you take:

 
<Grid>
<Grid.DataContext>
<!--- You will need add the plumbing for the “leader” ObjectType--->

<ObjectDataProvider xmlns:local="clr-namespace:PersonnelClasses"
                                      ObjectType="{x:Type leader:Managers}"

MethodName="GetManagers" />
</Grid.DataContext>

<!--- Add resources here –>
</Grid>

The GetManagers method returns the Managers collection.  You need to display the managers in a TreeView control.

When a user expands a Manager name, the name and hire date of all employees that report to each manager should be displayed beneath the Manager node.

What do you add to the Grid to show off your manager’s excellent leadership?

<Grid.Resources>
<DataTemplate x:Key="TeamMemberTemplate">
          <TextBlock>
                   <TextBlock Text="{Binding Path=Name}" />
                   <TextBlock Text="{Binding Path=Sales}" />
          </TextBlock>
</DataTemplate>

<HierarchicalDataTemplate x:Key="ManagerTemplate"

                                                 ItemsSource="{Binding Path=TeamMembers}"
                                                 ItemTemplate="{StaticResource TeamMemberTemplate}">
                    <TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
</Grid.Resources>
<TreeView ItemsSource="{Binding Path=.}" ItemTemplate="{StaticResource ManagerTemplate}"
/>

Later blogs will discuss the various items.  Maybe