ListView Inside Child TreeViewItem?

Hey guys, I have a WPF TreeView that has three nodes, I would like the last child (the third node) to contain a ListView populated with my bound data. The issue that I'm running into is that if I put a ListView in the ItemTemplate of my HierarchicalDataTemplate I get a ListView for each child rather than a single ListView with content. This is expected behavior per the documentation, but I'm looking for a work around (possibly modify the ItemContainerStyle), unfortunately I have virtually no experience with the TreeViewItem's control template, or for that matter much experience with TreeViews in general.

I've looked at the posibility of using a TreeListView but it doesn't fit my use case, nor does binding a separate control and displaying data that way.

Has anyone either already gone through the headache of sandwiching a ListView into a TreeViewItem, or can someone suggest how to modify the ControlTemplate to accomplish this?

Thank you, Aj

Answers


The node that has the Listview should be a different data type than the other two nodes so it can be handled differently by the Treeview. Also it sounds like the child that contains the list view data should not be in a HierarchicalDataTemplate but a regular DataTemplate one, since it doesn't have other child elements recognized by the Treeview. You can mix and match HierarchicalDataTemplate and regular DataTemplates in a Treeview as you see fit, regular DataTemplates represent "leaf" nodes, they don't have any children.

sample with different data types used in Treeview but still using hierarchical templates:

<HierarchicalDataTemplate DataType="{x:Type FooNormal}" ItemsSource="{Binding TreeviewChildNodeCollection}">
   // do something else here.
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type FooList}" ItemsSource="{Binding TreeviewChildNodeCollection}">
  <ListView  ItemsSource="{Binding ListviewChildNodeCollection}">
   //use listview here
  </ListView>
</HierarchicalDataTemplate>

Turns out the easiest way to deal with the situation is to replace the HierarchicalDataTemplate on the second node with an Expander, set the ItemsSource on the ListView rather than the HierarchicalDataTemplate, and restyle the button on the Expander to look like the one from a TreeViewItem....sorta a hack but it works :)

Thanks for all the help,

Aj


Need Your Help

Can you combine multiple images into a single one using JavaScript?

javascript image-processing image-manipulation

I am wondering if there is a way to combine multiple images into a single image using only JavaScript. Is this something that Canvas will be able to do. The effect can be done with positing, but ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.