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
|
Hi, I want to add text to the connection points on the left and right edges but use the default style for the connection points on top and bottom edges. I have seen examples for ConnectionStyleSelector. How do I use the same concept for connection points? Also, for a given connection point, can the style be changed based on a trigger? Thanks. |
|
|
Hello You can control the look of connection points through the ConnectionPointTemplateSelector property of the DiagramFormatter. A good example of this is in the ConnectionPointValidation.FlowDiagrams sample provided with WPF Diagrams. (See MainWindow.xaml) Create one or more DataTemplates to define the look of the connection points. Then either use a FixedTemplateSelector or a MatchingTemplateSelector with custom IDataTemplateMatchers to pick the appropriate DataTemplate for each connection point. Within the DataTemplates, you can use triggers to listen to connection point properties and change their look. So you could either create a single template that uses a trigger to change the position of the text, or you could create 3 separate templates and use a cusomt IDataTemplateMatcher to pick one based on the Edge property. Note that using a template selector only gives you control over the look of the connection points, not their behavior. i.e. the way they appear or disappear based on mouse interactions is controlled by a style deeper in the core of the product. It is still possible to override this though, so if you need to customize the behavior of connection points based on mouse interaction, let me know. Let me know if you have questions about any of this. -Jason Fauchelle |
|
|
Thanks Jason. I am able to make progress now. Another question. I am using TreeLayoutAlgorithm and want to set the IsReadOnly property to True in ms:DiagramSurfaceElement. However, on doing this, none of the connection points are visible (or enabled). If I set IsReadOnly to False then the connection points become visible. How can I make the connection points visible when IsReadOnly is set to True. |
|
|
Hello The best way to do this is to override the core DiagramNodeElement style. The downside to this is it is quite a large bit of code, and needs to be applied by defining a custom node style for each of your different types of nodes (which you probably want to do anyway). The upside is that from this code you can control a lot of the behavior and look of nodes. I've attached a text file containing most of the code you need. The first few bits are just some simple required resources. The next large chunk is the core diagram node style containing the layout of the various interaction controls and a lot of triggers that define the visibility of each control in various readonly scenarios. Then right at the end is the "entry point" of the core node style which determines when to use a simple light-weight node template, or the heavier full node template which helps improve performance. In the full node template you will see I have commented out one of the triggers which will allow connection points to be visible even in readonly mode. Copy all this code into a xaml resource dictionary used by your application. Then, if you are not yet applying custom node styles to your node implementations, you'll need to do this now. This is done by setting the NodeStyleSelector property of a DiagramFormatter. Similar to ConnectionStyleSelector which you are already familiar with. The ActivityDiagram sample has examples of applying custom node styles. Now, all you need to do is set the BasedOn property of each custom node Style to point to the DiagramNodeStyleBase resource in the code I provided. (Note that BasedOn is a property on the Style tag itself, don't use a Setter). Let me know if you have questions about any of this. -Jason Fauchelle |
|
|
Hi Daniel, I started with the code from HierarchicalDiagramDemo (from another thread) that uses a ToggleButton to hide/show certain sections of the tree. How do I modify DiagramNodeStylBase from the sample you sent in previous post to use ToggleButton? Basically I need to combine the code you send in previous post with the HierarchicalDiagramDemo. Thanks.
|
|
|
Hello Since you are following the HierarchicalDiagramDemo, this makes things a bit easier. You will notice that a lot of the code is similar between the hierarchical diagram demo styles and the file I sent. You can replace the BaseNodeStyle that you currently have from that demo with the FullDiagramNodeTemplate and DiagramNodeStyleBase from the file. Also, remove the OverridesDefaultStyle setter from the DiagramNodeStyleBase. Then your node styles can be BasedOn the DiagramNodeStyleBase. Let me know how this goes. -Jason Fauchelle |
|
|
Thanks Jason. I am making progress. HierarchicalDiagramDemo uses the IsChecked property of ToggleButton control to determine whether to make the node visible or not. How can I introduce a similar property for FullDiagramNodeTemplate ? |
|
|
Hello Good to hear you are moving forward. You should still be able to have the IsVisible trigger on the high level node styles - that is, the same style that sets the NodeTemplate property. Let me know if you run into any trouble. -Jason Fauchelle |
|
|
Hi Jason, This worked. Thanks. Do you have an example of how to set the MouseDownEvent or MouseDoubleClickEvent for DiagramNodeElement? Below is the code relevant to setting the style for the node. Most of it is what you had provided before
|
|
|
Hello The way I would recommend to listen to mouse actions on a node is to actually add an event handler to the DiagramSurface to pick up all such events like this:
(Where ds is the DiagramSurface instance). Then in the NodeDoubleClick handler, call a method we provide on the DiagramSurface to get the node under the mouse point like this:
The other alternative is to attach events to the MoveThumb of the custom node template. This has slightly better performance, but is more difficult to manage as you would need to add a code-behind file for your xaml resource file, and also traverse the visual tree to get from the MoveThumb to the DiagramNodeElement in the handler. -Jason Fauchelle |
|
|
Thank you |
|