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

Selected node not brought forward?

7 Answers 158 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Kristoffer
Top achievements
Rank 1
Kristoffer asked on 06 Feb 2013, 08:58 AM
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);

7 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 07 Feb 2013, 09:48 AM
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.

0
Kristoffer
Top achievements
Rank 1
answered on 07 Feb 2013, 10:20 AM
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(),
    ...
};
0
Pavel R. Pavlov
Telerik team
answered on 07 Feb 2013, 03:16 PM
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.

0
Kristoffer
Top achievements
Rank 1
answered on 07 Feb 2013, 03:33 PM
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...?
0
Pavel R. Pavlov
Telerik team
answered on 12 Feb 2013, 01:00 PM
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.

0
shushupti
Top achievements
Rank 1
answered on 13 Jun 2016, 12:39 PM
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
0
Petar Mladenov
Telerik team
answered on 16 Jun 2016, 10:41 AM
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.
Tags
Diagram
Asked by
Kristoffer
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Kristoffer
Top achievements
Rank 1
shushupti
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or