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

Using the Diagram Commands from code

6 Answers 79 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 23 Oct 2012, 06:45 PM
Hi

I have an application that uses a ribbon tab that is dynamically loaded. On this tab i want to include some diagram commands such as "BringToFront".

I cannot use the command binding because i don't find how to set the command target to the diagram... since this diagram is located on a view that is not directly coupled to the tab.

So i thought, i'd just create a regular command and then execute the commands from code, but i can not find any documentation on how to do this.

I have found

diagram.BringToFront(...);


But it has a parameter which i don't know how to set it:
List<IDiagramItem> lst = new List<IDiagramItem>();
      lst.Add(diagram.SelectedItem as IDiagramItem);
      diagram.BringToFront(lst.ToEnumerable());                   

This code refuses to compile with "Unknown Method".

How do i use these methods?

Best Regards,

Peter

6 Answers, 1 is accepted

Sort by
0
Accepted
Miro Miroslavov
Telerik team
answered on 24 Oct 2012, 07:37 AM
Hello Peter,

 You can use the BringToFront method as follows: 

diagram.BringToFront(diagram.selectionService.SelectedItems);
The parameter of the method is IEnumerable<IDiagramItem>, where IDiagramItem could be any Shape or Connection, so you can pass just a List<RadDiagramShape> or List<RadDiagramConnection> or any other collection of those types.
Hope this helps. 

Regards,
Miro Miroslavov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
HDC
Top achievements
Rank 1
answered on 24 Oct 2012, 12:21 PM
Hi Miro,

No such thing as an "SelectionService" object on the Diagram component, unless this is 2012 Q3 ?

I solved it this way:
private void Arrange(object sender)
 
{
 
List<RadDiagramShapeBase> lst = new List<RadDiagramShapeBase>();
 
 
lst.Add(diagram.SelectedItem as RadDiagramShapeBase);
 
switch (sender.ToString().ToLower())
 
{
 
case "bringtofront":
 
diagram.BringToFront(lst);
 
break;
 
case "sendtoback":
 
diagram.SendToBack(lst);
 
break;
 
case "bringforward":
 
diagram.BringForward(lst);
 
break;
 
case "sendbackward":
 
diagram.SendBackward(lst);
 
break;
 
}
 
lst.Clear();
 
}

Best Regards,

Peter
0
Miro Miroslavov
Telerik team
answered on 25 Oct 2012, 06:35 AM
Hello peter,

 Sorry for that. Actually the SelectionService is our internal service that is not publicly visible. What you're doing is possible solution, indeed. But if you have multiple selection, you may need to loop all the selected items. Also there is one other way to that: 

IEnumerable<IDiagramItem> selectedItems = diagram.SelectedItems.Select(i => diagram.ContainerGenerator.ContainerFromItem(i));
This will return you all the selected items of type IDiagramItem.

Greetings,
Miro Miroslavov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Deepak Shakya
Top achievements
Rank 1
answered on 27 Feb 2015, 06:40 AM
Thanks Miro for the solution. It would be good if this was in the documentation.
0
Barış
Top achievements
Rank 1
answered on 22 Aug 2015, 02:48 PM

Hello, 

I also needed this feature thanks. but I still need something like that for both Align and Group function. Below solutions fails on runtime.  

if (!this.Diagram.SelectedItems.IsNullOrEmpty())
           {
               var items = new List<IGroupable>();
               foreach (var item in this.Diagram.SelectedItems)
               {
                   items.Add(item as IGroupable);
               }
 
               this.Diagram.Group(string.Empty, true, items.ToArray());
           }

public void Align(Alignment alignment)
{
    if (!this.Diagram.SelectedItems.IsNullOrEmpty())
    {
        var items = new List<IShape>();
        foreach (var item in this.Diagram.SelectedItems.Where(x => x is IShape))
        {
            items.Add(item as IShape);
        }
 
        this.Diagram.Align(alignment, items);
    }
}

0
Kiril Vandov
Telerik team
answered on 26 Aug 2015, 11:21 AM
Hello Barış,

I am not sure what is the feature you are referring to as in the forum post there are two different problems and solutions for them. That is why I would like to ask you to open a new tread describing your scenario in details as the result you want to accomplish.
Doing so we will be able to better understand your scenario and provide you with the best possible solution. Also it will help us and the community to better track the different treads as they will solve one problem only, not multiple.

Thank you for your understanding. Looking froward to hearing from you.

Kind regards,
Kiril Vandov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Diagram
Asked by
HDC
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
HDC
Top achievements
Rank 1
Deepak Shakya
Top achievements
Rank 1
Barış
Top achievements
Rank 1
Kiril Vandov
Telerik team
Share this question
or