Selected node not brought forward?

8 posts, 0 answers
  1. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 06 Feb 2013 Link to this post

    When I select a node in my diagram, I can see the selection border on top of all nodes. The selected node, however, remains below any nodes placed above it. I want selected nodes to be brought forward. How can this be accomplished?

    Thanks

    Update
    I tried this playing with the SelectionChanged event, but I can't figure out how to use it:

    private void diagram_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count > 0)
        {
            if (e.AddedItems[0] is MyNode)
            {
                // new List<IDiagramItem> { ??? };
                // this.diagram.BringToFront(e.AddedItems); // Shape??
            }
        }
    }

    Update 2
    I also tried the following, but it doesn't work at first. After playing a bit with the nodes, it seems to start working. I believe I have to scroll/zoom a bit first? Looks like a bug to me.

    DiagramCommands.BringToFront.Execute(null, this.diagram);
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 07 Feb 2013 Link to this post

    Hello Kristoffer,

    I am not sure that I understand your scrolling/zooming issue. However, I achieved the desired behavior with the following code:

    private void xDiagram_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count != 0)
        {
            var shape = e.AddedItems[0] as RadDiagramShape;
            if (shape != null)
            {
                List<RadDiagramShape> ls = new List<RadDiagramShape>();
                ls.Add(shape);
                this.xDiagram.BringToFront(ls);
            }
        }
    }

    Please try this snippet out and let me know if it works for you and if it solves your scrolling/zooming issue.

    Regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 07 Feb 2013 Link to this post

    Thanks for your answer.

    The problem is that e.AddedItems does not contain shapes. In my case it contains node instances. When I drag and drop items from the diagram panel, a shape is created with its DataContext set to an instance of MyNode. That's the item I see in this SelectionChanged event.

    Consequently, I cannot get the shape since I have its child.

    public class MyNode : NodeViewModelBase { ... }

    // On drag'n'drop:
    var chartShape = new MyShape()
    {
        DataContext = new MyNode(),
        ...
    };
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 07 Feb 2013 Link to this post

    Hi Kristoffer,

    In order to gain access to the shape you can use the ContainerFromItem() method of the RadDiagram's ContainerGenerator and pass your business object as a parameter. After that you can use the code from my previous post. For your convenience I implemented this approach in the attached project. Please take a look at it and let me know if it works for you.

    All the best,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 07 Feb 2013 Link to this post

    Thanks. That helped!

    However :) There seems to be a bug (or error in my code). When my selected shape is brought to front, it is still obscured by shapes that I have not previously selected. Hence, if I manually select all shapes in my graph, your code works. If I don't select them, the operation is a no-op. This problem can only be seen for drag'n'dropped shapes!

    I'm wondering if I need to explicitly set the ZIndex variable when I'm dragging my shapes to the graph. Still, I would assume that this is handled automatically by the diagram...?
  7. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 12 Feb 2013 Link to this post

    Hello Kristoffer,

    The RadDiagram control uses Canvas panels in it's ControlTemplate and it orders the last added shape (element) on top of all others. At the same time the BringToFront() method also sets the z-index of the selected shape to the highest possible and this is why you drop behind the existing shapes. In order to overcome this behavior you can subscribe to the Drop event and use the BringToFront() method on the newly added shape. Keep in mind that you will also have to define the OnDrop event handler to handle already handled events:

    DragDropManager.AddDropHandler(this.xDiagram, OnDiagramDrop, true);

    All the best,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. shushupti
    shushupti avatar
    1 posts
    Member since:
    Jun 2016

    Posted 13 Jun in reply to Pavel R. Pavlov Link to this post

    Hi team, i am creating a different thread,as i am not able to generate new ticket.i have tried the solution which is posted above but its not working for me.
    As we are using forward,backward,tofront and to back functionality of diagram control which is of  telerik in our application.for example when we are taking 3 diagrams and putting it into layers like one above the other,then when we click on forward button it directly comes at front instead of coming by one position forward i.e it  directly comes at front instead of coming to second place and same issue is for backward button
    The version of dll which we are using is
    version-2013.1.220.40 ,
    Runtime version-v4.0.30319.
    can you please  reply and provide the solution for this issue.

    Thanks in advance
  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 16 Jun Link to this post

    Hi shushupti,

    We are a little confused from your explanation - we are not sure how your diagrams are on top of each other and how this is related to bring totop/ tofront / forward issue. However, since your version is old and you may have hit an old issue in RadDiagram, we highly encourage you:
    - either to upgrade to the latest version and check if this is still reproducible
    - or work only with Canvas.ZIndex attached property. Instead of using the Diagram Commands simply introduce methods which control the ZIndex property.
    If these are not an options for you please elaborate a bit more on your scenario with some sample code and what you expect exactly. 

    Regards,
    Petar Mladenov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready