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
Comments
Anonymous
June 27, 2011
I hate these things too. A trick we do here is make an XML tree out of items for the display using a binary stream. Then we set the bindings to point to the properties of the xml nodes.Anonymous
July 01, 2011
Louis, Yeah, this is just a overly complex controlin my opinion, on the other hand if I was ask how would I improve the design, I couldn't do it. Or could I? The cool thing about software is that if I don't like something I can build a better thingie and try to sell it. Louis, thank you for your comment, if you company has a website feel free to post it here. I won't guarantee that I will allow it to post (for example there are, let's say visually stimulating websites).