TreeView
Download Source Code In this section we will show you the TreeView. It shows you how to:
|
The DataContext of the TreeView is the OrgTreeViewModel. We set the TreeView's ItemsSource to the Root property of the OrgTreeViewModel, which is the top-most node in the hierarchy.
The HierarchicalDataTemplate's ItemsSource is set to the Children property. Notice that the Children property is from the OrgElementViewModel and not from the OrgTreeViewModel. This is because the TreeView's HierarchicalDataTemplate uses the type returned from the Root property and looks for the binding property from the type returned, which is the OrgElementViewModel:
Each node in the tree is just a display of the image and the text of a person's name using the OrgElementViewModel:
Since each node has the OrgElementViewModel as the DataContext, we bind the TreeViewItem's IsSelected property to the IsSelected property of the OrgElementViewModel to highlight the node's background to LightBlue when a node is selected using DataTrigger:
When an user clicks on a node in the tree we need to let the ViewModel node know that the selection has changed. We like to route the event as a command to the ViewModel, yet the TreeView does not have built in Command property. This can be accomplished by adding the System.Windows.Interactivity library and we can still pass the SelectedItem of the TreeView to the CommandParameter when the selected item has changed:
Then in the OrgTreeViewModel we just set the Selected property to the node when the command is fired, which in turn sets the IsSelected property of the node to true:
Next we will show you the Navigation View.
Future series of articles on sharepoint:
- sharepoint list -- the concepts of sharepoint list and how to effectively manage it
sharepoint version control -- the internals of sharepoint version control and how to administer and manage the versions
sharepoint permissions -- how to manage the permissions in a large enterprise sharepoint environment
sharepoint server farm -- how to set up a high availability sharepoint server farm
sharepoint document library -- the details on how to get your ways around the document library in sharepoint
sharepoint configuration -- the configurations needed for different sharepoint network scenarios
sharepoint css -- making the most out of customizing sharepoint frontend
sharepoint web services -- some of the most convienent ways to communicate with the internals of sharepoint