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
|
If i have one connection point with two connections, labels "Data" overlap. See attached file. How can i solve this problem? |
|
|
Hello We don't currently provide automatic support for this, but there is a way for you to provide custom label positioning logic to work around it for now. I have attached a sample that demonstrates how to create a custom connection style which places the connection content near the center of the connection path. This is achieved using the ConnectionContentTransformConverter you will find in the sample. You can create a converter like this to customize the position of the labels. So for example you could create a converter that places the labels a certain distance along the total connection path. In the example that you attached, this could cause one of the labels to be placed after the bend in the connection. You are not limited to an IValueConverter, you can use a multi value converter instead if you need multiple property values. So you could include the connection model object so that the converter can evaluate the number of connections attached to the same connection to best determine where the labels should be placed. To run the sample, make sure to include a reference to your copy of WPF Diagrams 2.0. When the sample is running, add 2 nodes to the diagram and connect them together with a connection. When you hover the mouse over a connection, you will see the content text box is near the center of the connection rather at the source. The custom connection style can be found in the App.xaml file. On line 180 you will find the ContentPresenter that displays the connection data. The render transform has been set using the ConnectionContentTransformConverter to achieve the effect. Let me know if you need further help with customizing the label positions the way you want. |
|
|
I combined your example with source code of ConnectionContentTransformConverter.
Benefits:
1. Position depends on Edge
2. TextBox "Data" is above segment
3. If no collisions, "Data" is above first segment.
ConnectionStyles.xaml
<ContentPresenter.RenderTransform>
<MultiBinding Converter="{StaticResource ConnectionContentTransformConverter}">
<Binding Path="Connection.Segments" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="FromConnectionPoint.Edge" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="ActualHeight" Mode="OneWay" ElementName="DataPresenter" />
<Binding Path="ActualWidth" Mode="OneWay" ElementName="DataPresenter" / </MultiBinding> </ContentPresenter.RenderTransform>
ConnectionContentTransformConverter.cs
public
object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
var segments = values[0] as ObservableCollection<DiagramConnectionSegment>;
var edge = (Edge)values[1];
var contentWidth = (double)values[2];
var contentHeight = (double)values[3];
if (segments.Count == 0)
return new TranslateTransform(0, 0);
float divisor = segments.First().Connection.FromConnectionPoint.Connections.Count == 1 ? 5 : 3;
int middleIndex = (int)Math.Floor(segments.Count / divisor);
DiagramConnectionSegment middleSegment = segments[middleIndex];
double segmentX = (middleSegment.StartPoint.X + middleSegment.EndPoint.X) / 2.0;
double segmentY = (middleSegment.StartPoint.Y + middleSegment.EndPoint.Y) / 2.0;
double x = segmentX;
double y = segmentY - contentHeight;
if (edge == Edge.Bottom) y = segmentY;
else if (edge == Edge.Left) x = segmentX - contentWidth;
return new TranslateTransform(x, y); } |
|