BoldSign®Effortlessly integrate e-signatures into your app with the BoldSign® API. Create a sandbox account!
Hello! I use SfDiagram in MVVM style. I have read this article and tried using this aproach. https://support.syncfusion.com/kb/article/10082/how-to-get-or-set-the-positions-of-the-segments-by-programmatically-in-wpf-diagram?isInternalRefresh=False
1. I can't use this code before loading sfdiagram, because Info is null at that moment , so I need to use loaded event.
segmentpoints = new List<Point>() { new Point(20, 20), new Point(30, 30) }; (connector.Info as IConnectorInfo).LoadSegments(segmentpoints);
When try it , it also doens't work , I really don't know why, so I decide create segments collection in this way:
this.Segments = points.Select(x => new StraightSegment() { Point = x }).ToList();
2. When I need to get point collection of segments, it's real problem, because this approach doesn't work too. I receive 3 points, but I have 2 straightsegments and, as I understand, I need to get 2 points.
(connector as ConnectorViewModel).Info as IConnectorInfo).ToPoints();
Ok, no problem, I find Solution in manner below. But I really need use dynamic because I can't cast Segments to any type. I use different collections, classes, etc. Nothing doesnt work (dynamic works certainly)
Please, this code works, but Could you give me advice how I can refactor this, or , at least, give me name of interface, class, etc, to which I can cast Segments. Thanks.
foreach (var connector in Connectors as IEnumerable<ConnectorViewModel>)
{
dynamic list = connector.Segments;
var points = new List<Point>();
foreach (var segment in list)
{
if (segment.Point != null)
{
points.Add(segment.Point);
}
}
}
Hi Aksel,
Requirement: How to get or set the position of connector segment points programmatically?
We have validated the code you provided. The LoadSegments() method is used to load segment points during runtime for an existing connector that has already been added to the diagram. If you want to add segments during the initialization of the connector itself, we suggest using the connector's Segments property. Below, we provide an example of adding a single straight segment to a connector and a connector with multiple straight segments.
// To create a straight connector between two points. var connector1 = new ConnectorViewModel { SourcePoint = new Point(100, 100), TargetPoint = new Point(200, 200), Segments = new ObservableCollection<IConnectorSegment> { new StraightSegment() } }; connectors?.Add(connector1);
// To create a straight connector with multiple segments. var connector2 = new ConnectorViewModel { // Define the start point for the connector. SourcePoint = new Point(400, 400), // Define the end point for the connector. TargetPoint = new Point(600, 550), // Define the intermediate points for the connector. Segments = new ObservableCollection<IConnectorSegment> { new StraightSegment { Point = new Point(500,380) }, new StraightSegment { Point = new Point(500,460) }, } };
connectors.Add(connector2);
|
To access the segment points of the connector, we suggest using the ToPoints() method with the argument set to true.
var connectorInfo = connector.Info as IConnectorInfo; List<Point> segmentsPoints = connectorInfo.ToPoints(true).ToList(); |
For your convenience, we have shared a sample that displays the segment points of the connector upon selecting it.
Regards,
Arun Kumar S
Tnanks for responce.
This code doesn't work as I need it to because I only need to get intermediate points. Of course I can get a collection without first and last element, but maybe is there a more elegant approach?
Hi Aksel,
Requirement: How to get or set the position of connector
segment points programmatically?
The ToPoints method is the only possible way to get the Segmentpoints of a
Connector. If you provide the details of your requirements, we'll attempt to
explore any other available options to achieve them.
Regards,
Arun Kumar S
You have provided me example above. In that example you created next:
var connector2 = new ConnectorViewModel
{
// Define the start point for the connector.
SourcePoint = new Point(400, 400),
// Define the end point for the connector.
TargetPoint = new Point(600, 550),
// Define the intermediate points for the connector.
Segments = new ObservableCollection<IConnectorSegment>
{
new Syncfusion.UI.Xaml.Diagram.StraightSegment { Point = new Point(500,380) },
new Syncfusion.UI.Xaml.Diagram.StraightSegment { Point = new Point(500,460) },
}
};
And then, when you use The ToPoints method , it returns 4 points with Source and Target.
But in my app, when I debug it, The ToPoints method returns me 3 points, and it's unexpectedly.
Ok, no problem, I can compare points with Target and Source to get only intermediate points, but, imho, this approach is quite strange
Hi Aksel,
Reported issue: The ToPoint method does not return the proper value.
We are trying to reproduce the reported issue in the simple sample. However, we are unable to reproduce the reported issue on our end. We suspect you have modified the segment points by editing the connector in the runtime. Please ensure that. If you are still facing the same issue please share a simple sample to reproduce the reported issue with a video reference for the replication procedure.
Regards,
Arun Kumar S
Hi Aksel,
Reported Issue: The ToPoint method does not return the proper value
We have validated the reported issue based on the provided sample and can reproduce the reported issue. On further validation, we found that the reported issue is not an issue, it's the actual behavior in our SfDiagram control. In the ToPoints method, if we pass the argument as 'true', it returns all segment points including the source and target points. However, if no parameters are passed, it only returns intermediate and target points.
Requirement: How to get the intermediate points for the connector.
We are still working on getting the segment points alone. We will update you with more details on April 12, 2024.
Regards,
Arun Kumar S
Hi Aksel,
Requirement: Need to get the Segment points of the Connector.
Currently, the ToPoints method in the ConnectorInfo is the only feasible method to get the segment points of a Connector.
The argument of the ToPoints method as False:
If you pass the argument as false or without arguments, it will return the endpoints of the segments available in the Segments collection of the Connector. But in real-time some internal segments will be calculated to create connectors properly.
The argument of the ToPoints method as True:
If you pass the argument as true, it will return all the endpoints of the segments available in the Segments collection of the Connector with the internally calculated segment points along with the Source and Target points of the Connector. Please remove the first and last point in the list returned by the ToPoints method to meet your requirements.
Regards,
Karkuvel Rajan S