Reputation: 51084
I have the following markup in a ServiceTree
control, which should present a TreeView
of services in a ServiceGroup
:
<Grid>
<TreeView ItemsSource="{Binding Services}" DataContext="{Binding}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type businessService:BusinessService}">
<TreeViewItem Header="{Binding Name}"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
In the top level binding, Services
is the collection of services that belongs to a ServiceGroup
.
In the main window, I use the following data binding to create an OdcExpander
from the Odyssey project:
<ItemsControl.ItemTemplate>
<DataTemplate DataType="groups:ServiceGroup">
<odc:OdcExpander Header="{Binding UIMetadata.MenuText}" HeaderBackground="{Binding UIMetadata.MenuTabBackColor}">
<XTime900Shell:ServiceTree />
</odc:OdcExpander>
</DataTemplate>
</ItemsControl.ItemTemplate>
This works. I get one expander correctly bound to each ServiceGroup
, but on the groups with services, i.e. the "Employees" group, there is a space where the treeview should be, proportional in height to the number of services it should show, so it is binding to the Services
collection property, and creating an item for each service, but not displaying anything for the service 'Name` property, which I know is correctly populated.
Upvotes: 0
Views: 603
Reputation: 4760
I think the error is that your are using a TreeViewItem, you should not. If you are creating a data template you can show any visual item, for instance a text block. The tree view item will be the container item, that you will show as a text box (for instace). you should do like this:
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type businessService:BusinessService}">
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
Hope works...
Upvotes: 1