MulticolumnTreeView

Using the MulticolumnTreeView

The MulticolumnTreeView control extends the Silverlight SDK TreeView control to support showing multiple columns in a grid or ListView-like format.

To set up the columns of a MulticolumnTreeView, follow the same instructions as for a ListView.

In addition to defining the columns, you must also tell the MulticolumnTreeView how to determine the children for each item in the tree. To do this, you must provide an ItemTemplate of type HierarchicalDataTemplate, with its ItemsSource property set to tell the tree how to expand the hierarchy.

Here is an example in which the sub-items for each item in the tree are derived from the Children property:

CopyExample Usage
<ms:MulticolumnTreeView Name="mctv" Margin="30" Grid.Column="1" ItemsSource="{Binding}">
  <ms:MulticolumnTreeView.ItemTemplate>
    <swc:HierarchicalDataTemplate ItemsSource="{Binding Children}" />
  </ms:MulticolumnTreeView.ItemTemplate>
  <ms:MulticolumnTreeView.Columns>
    <ms:GridViewColumn Header="Name" Width="100" DisplayMemberBinding="{Binding Name}" />
    <ms:GridViewColumn Header="Owner" Width="100" DisplayMemberBinding="{Binding Owner}" />
    <ms:GridViewColumn Header="Height" Width="100" DisplayMemberBinding="{Binding Height}" />
  </ms:MulticolumnTreeView.Columns>
</ms:MulticolumnTreeView>

See ListView for further examples.

To use different expansion paths at different levels of the tree, set HierarchicalDataTemplate.ItemTemplate to be the template for the next level down.

Note that any content in the HierarchicalDataTemplate is ignored. Items in a MulticolumnTreeView are displayed in a tabular format according to the Columns property, and cells are presented according to the column’s settings.

Customizing the MulticolumnTreeView Control

You can customize a MulticolumnTreeView in the same way as a ListView.

In addition, you can customize the expand/collapse user interface by setting the ExpandingDecorator property. This property contains a template which the MulticolumnTreeView wraps around the leftmost column. The default template is identified by the ExpandingCellTemplateKey.

Templating the MulticolumnTreeView

When templating the MulticolumnTreeView, your template should base its layout on the WrappedColumns property, not the Columns property. This ensures that your template will inherit the expand/collapse user interface supplied by the MulticolumnTreeView. If you do not do this then users of your template will have to supply their own expand/collapse user interface as part of their CellTemplates.