Using the Diagram Commands from code

7 posts, 1 answers
  1. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 23 Oct 2012 Link to this post

    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

  2. Answer
    Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 24 Oct 2012 Link to this post

    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.

  3. DevCraft banner
  4. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 24 Oct 2012 Link to this post

    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
  5. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 25 Oct 2012 Link to this post

    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.

  6. Deepak Shakya
    Deepak Shakya avatar
    118 posts
    Member since:
    Aug 2007

    Posted 27 Feb 2015 in reply to Miro Miroslavov Link to this post

    Thanks Miro for the solution. It would be good if this was in the documentation.
  7. Barış
    Barış avatar
    19 posts
    Member since:
    Jul 2015

    Posted 22 Aug 2015 Link to this post

    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);
        }
    }

  8. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 26 Aug 2015 Link to this post

    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
Back to Top
DevCraft banner