WPF - DataTemplate to show only one hierarchical level in recursive data
Posted
by Paull
on Stack Overflow
See other posts from Stack Overflow
or by Paull
Published on 2010-05-08T12:12:49Z
Indexed on
2010/05/08
12:18 UTC
Read the original article
Hit count: 352
Hi all,
I am using a tree to display my data: persons grouped by their teams. In my model a team can contain another team, so the recursion.
I want do display details about the selected node of the tree using a contentpresenter. If the selection is a person, everything is fine: I can show the person name or datails without problem using a simple datatemplate. If the selection is a team I would like to display the team name followed by a list of member names. If one of these members is another team I would like to display just the team name, without recursion...
My code here is wrong because it displays data in a recursive way, what is the right way of doing it?
Thanks in advance for any help!
best regards,
Paolo
<ContentPresenter Content="{Binding Path=SelectedItem, ElementName=PeopleTree}" >
<ContentPresenter.Resources>
<DataTemplate DataType="{x:Type my:PersonViewModel}">
<TextBlock Text="{Binding PersonName}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type my:TeamViewModel}">
<StackPanel>
<TextBlock Text="{Binding TeamName}" />
<ListBox ItemsSource="{Binding Members}" />
</StackPanel>
</DataTemplate>
</ContentPresenter.Resources>
</ContentPresenter>
© Stack Overflow or respective owner