I'm interested in creating a data-mapping tool using XamDiagram that would be similar to the Class Diagram sample that you ship with the 2014.1 WPF samples. The main difference is that I would also like to create a connector from a property in one class to a property in a target class. I still want the capability of adding connectors between classes, just want the added ability to create connectors between properties. Is this possible using the XamDiagram CTP?
Thanks.
Michael Collins
Hello Michael,
You will probably need to provide custom connection points that are positioned next to the properties where you'd like to have them. If your properties are evenly spaced inside the shape then positioning the connection points shouldn't be overly difficult. I'm working on a sample to try this out. I will update you again once it is ready.
Hi Michael,
Like I said previously, you will need to create connection points on the DiagramNodes that line up with the properties you want to have them. You can create these points fairly simply by handling the Loaded event on the TextBlocks used to render the property names in your DataTemplate. Inside the loaded event, you can find the pixel location of the TextBlock relative to the DiagramNode and then calculate where to attach the connection point. The code would look like this:
// connection points require a unique name private static int ConnectionPointIndex = 0; private void TextBlock_Loaded(object sender, RoutedEventArgs e) { TextBlock txt = sender as TextBlock; // get the diagram node. DiagramNodePresenter nodePresenter = (DiagramNodePresenter)Infragistics.Windows.Utilities.GetAncestorFromType(sender as DependencyObject, typeof(DiagramNodePresenter), false); // figure out where the TextBlock's pixel coordinates are relative to the diagram node. var transform = txt.TransformToVisual(nodePresenter); Point absolutePosition = transform.Transform(new Point(0, 0)); // place the connection point double pos = (absolutePosition.Y + (txt.ActualHeight * 0.5)) / nodePresenter.ActualHeight; nodePresenter.Node.ConnectionPoints.Add(new ConnectionPoint("point" + ConnectionPointIndex.ToString(), new Point(1, pos))); ConnectionPointIndex++; }
If you run this code, you'll see connection points appear next to each of the "properties" in the diagram node. After all the nodes have finished loading, you'll then need to connect up the points by creating a DiagramConnection and adding it to the XamDiagram's Items collection. The DiagramConnection object has properties for StartNodeName and EndNodeName as well as StartNodeConnectionPointName and EndNodeConnectionPointName. These names correspond to the names of the DiagramNode and ConnectionPoint objects.
Hopefully this is enough to get you started. Let me know if you have any questions.
Do you still require assistance on this matter?
Have you had a chance to try this out? Let me know if you have any questions.
Thanks Rob. I'll try this out this weekend.