Draw a tree/graph with wpf? [Using Canvas or what?]
i would like to build my own control with a datasource. This control should draw a simp开发者_C百科le binary tree :-)
What should i use as drawing base? Should i use a canvas or should i override some paint event method like onRender()?
The nodes should be some sort of usercontrol.
Thank you.
Selecting a container should be driven by the features you need. Use a Canvas when you need absolute positioning.
However, the control could be an ItemsControl and you could use the Canvas in the ItemsPanel. After all the Canvas is just for display/arranging.
You can use the ItemsControlTemplate to set the DataTemplate for the nodes.
Have a look at hierarchical datatemplates at the end of this article
Perhaps all you have to do is create a template for the treeview control and subclass the treeview control to override the Arrange pass.
You can also learn from this approach by Josh Smith
精彩评论