开发者

WPF TreeView with multiple item sources

开发者 https://www.devze.com 2023-03-08 12:37 出处:网络
I am stuck on a problem with the wpf treeview control in my current application. I\'m building a visual studio like application (editor with project tree) for my school.

I am stuck on a problem with the wpf treeview control in my current application. I'm building a visual studio like application (editor with project tree) for my school.

Now i have the problem that I can't display this structure in my treeview.

I'd like to have the following structure:

+ Project
  - Folder
    -- Folder
   开发者_JS百科 -- File
  - Folder
  - File

+ Project
...

I've tried a lot of things I found around the internet, but not one of them really did work..

Thanks for your help.


Have you tried HierarchicalDataTemplate ? You can find solution here : http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx


Since you always mention that you need multiple ItemsSources i think your problem is that your project object has two collections: Files & Folders and you don't know how to put both of them into the HierarchicalDataTemplate's ItemsSource.

The solution to that is the CompositeCollection. Note that if you construct it in XAML you will not have a DataContext inside the CollectionContainers, so you cannot bind the Collection property that easily.


You'll have to use a DataTemplateSelector, see the example here:

http://www.switchonthecode.com/tutorials/wpf-tutorial-how-to-use-a-datatemplateselector

0

精彩评论

暂无评论...
验证码 换一张
取 消