This is a migrated thread and some comments may be shown as answers.

How to rotare a group

2 Answers 56 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Dario Concilio
Top achievements
Rank 2
Dario Concilio asked on 13 Jun 2017, 11:58 AM

Hi,
Can I rotate a group of some RadDiagramShape?

My problem is when I put beside more shapes and I group theme. Afterthat I would rotate a group to 90°

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 15 Jun 2017, 01:02 PM
Hello Dario,

To achieve your requirement you can create a custom RotationService. I prepared a small example demonstrating a possible approach which you use. You can find it attached to my post. Please give it a try and let me know if it helps.

Here is the service implementation:
public class MyRotationService : RotationService
{
    private double? customAngle = null;
 
    public MyRotationService(RadDiagram diagram)
        : base(diagram)
    {    
    }
 
    public void RotateGroup(IGroup group, double angle)
    {              
        var groupItems = group.Items.OfType<IDiagramItem>();
        this.InitializeRotate(groupItems, 0, group.GetBounds());
        this.StartRotate(new Point());
 
        this.customAngle = angle;
        this.Rotate(new Point());
        this.customAngle = null;
 
        this.CompleteRotate(new Point());
    }
 
    protected override double CalculateRotationAngle(Point newPoint)
    {
        if (this.customAngle.HasValue)
            return this.customAngle.Value;
        else
            return base.CalculateRotationAngle(newPoint);
    }
}
You can register the service using the following code:
this.diagram.ServiceLocator.Register<IRotationService>(new MyRotationService(this.diagram));
And you can use the custom service like this:
var group = this.diagram.Groups.ElementAt(0);
MyRotationService rotationService = (MyRotationService)this.diagram.ServiceLocator.GetService<IRotationService>();
 
var groupedItems = group.Items.OfType<IDiagramItem>();
rotationService.RotateGroup(group, 90);

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Dario Concilio
Top achievements
Rank 2
answered on 23 Jun 2017, 12:17 PM

Thank you, Martin.

Exactly what I needed.

I have other issues but I have already specific post about "delete all items of group"

Tags
Diagram
Asked by
Dario Concilio
Top achievements
Rank 2
Answers by
Martin Ivanov
Telerik team
Dario Concilio
Top achievements
Rank 2
Share this question
or