This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is there anyway to set the nodes datatemplate in code? I want to be able to specify a usercontrol at runtime and use the FrameworkElementFactory to set the datatemplate rather than using a xaml resource. |
|
|
The DataTemplate for a node is determined by the IDiagramFormatter.NodeTemplateSelector. You can create your own selector which, when appropriate, creates a DataTemplate/FrameworkElementFactory on the fly: public class DynamicNodeTemplateSelector : DataTemplateSelector { |
|
|
I have successfully implemented the a DataTemplateSelector like that above. I created a subclass of the FlowDiagramNode which has a property to return the NodeDataTemplate (see below). The DataTemplate selector simply uses the NodeDataTemplate property to resolve the data template set by the node implementor. These datatemplate are defined as user controls (typically with an image and label). This seems to work fine for displaying the datatemplate however I cannot move nodes around on the canvas. The diagram surface does not detect that the node is movable when I hover over it with the mouse. Is there some property I need to set on my usercontrol to allow this. public abstract class ActivityNodeBase : FlowDiagramNode
public class DynamicNodeTemplateSelector : DataTemplateSelector else return null; |
|
|
You need to set IsHitTestVisible="False" on the bits of your template (user control) that you don't want to be interactive. For example, if you user control consists of a TextBox sitting over a coloured Rectangle, you would set the Rectangle to have IsHitTestVisible="False" (but not the TextBox, because the user needs to be able to type into that). |
|