0

i would like to build my own control with a datasource. This control should draw a simple 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.

1 Answer 1

1

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

10
  • Yes you can do that but be aware that your code is now dependent on the existance of a canvas (with a specific name) in the template. In other words: a designer can't simply replace the template.
    – Emond
    Jan 17, 2011 at 10:34
  • In my control template i placed a canvas and i use this canvas for arranging some contentpresenters and displaying some lines. i also have a datasource property... but how can i build a generic property? you can build a tree with any object which has a list as member with objects of the same type. class person { list childs; } i would like that my control detects tree datasources and draws the tree... i dont would like to use one type of datasource or introduce a interface... what should i do?
    – user547064
    Jan 17, 2011 at 13:12
  • I added to my answer. My guess is you could simply create a subclass of the TreeView control.
    – Emond
    Jan 17, 2011 at 13:56
  • Sry i'm not able to follow you. I have my code that draws a tree graph. I use a node class to calc x and y values. The arrangement depends on the data... its not possible to change the panel... there is a sample tree yworks.com/img/net40/net_collapsible_tree.png
    – user547064
    Jan 17, 2011 at 14:05
  • I assumed the control was positioning its children and that in fact your control is the same as a TreeView Control with just a different layout. So I would subclass the TreeViewcontrol to arrange the child controls/nodes and draw the arrows and add a control template containing a canvas to accomodate the positioning.
    – Emond
    Jan 17, 2011 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.