This project is read-only.

I don't want the control to (re)layout when changes are made

Jun 24, 2010 at 10:12 AM
Edited Jun 24, 2010 at 10:12 AM
Hi all! To begin with - thanks for a really great control! I've worked from the example found in TestWindow.xaml in the Sample-project. I've begun with a quick and dirty drag and drop functionality which positions a vertex on the drop point like this: public void DoDragDropCallback(object sender, DragEventArgs e) { // layout is of type TestGraphLayout and lies inside the zoomcontrol on the page. Point position = e.GetPosition(layout); PocVertex v = new PocVertex("Some text on the VC"); layout.AddVertexInMyCustomMethod(v, position); // This is my custom method. } public class TestGraphLayout : GraphLayout<PocVertex, IEdge<PocVertex>, BidirectionalGraph<PocVertex, IEdge<PocVertex>>> { public void AddVertexInMyCustomMethod(PocVertex vertex, Point position) { _currentVertex = vertex; _currentPosition = position; base.Graph.AddVertex(vertex); // This forces a relayout of the graph (which I don't want it to do). } // Overridden method which is called when the forced relayout is done. protected override void InitializePosition(PocVertex vertex) { if (_currentVertex != vertex) { base.InitializePosition(vertex); } else { VertexControl vc = _vertexControls[_currentVertex]; SetX(vc, _currentPosition.X); SetY(vc, _currentPosition.Y); _currentVertex = null; } } } But the problem is that the graph is relayout:ed which moves the vertices around (I want the layout to be static until a user explicitly calls Layout() or ContinueLayout()). I understand that if I position a vertex outside the graphcanvas, i.e. outside it in the zoom-control I need to recalculate the size of the graphcanvas. But is there another way to solve this problem (i.e. use another graph than BidirectionalGraph) and is the retreived relative position correct in the DoDragDropCallback? Kind regards, Richard
Sep 15, 2010 at 6:49 AM

I'd like to know the same thing.  I want the user to be able to kick off an automatic layout on demand, but only when they demand it.  So when a user adds a vertex or adds an edge, nothing else changes except that the new vertex shows up or the new edge shows up.  The user would drag it where it wants it, and the user's layout would be respected until they initiated a re-layout.

 

Is that possible?

Mar 14, 2011 at 10:48 PM

"Is that possible?"
i guess not(((((((( 

Jan 10, 2013 at 12:53 PM

I need the same thing. The removed vertex should disappear but the others should maintain the position.

Jan 29, 2013 at 11:58 AM
Edited Jan 29, 2013 at 12:04 PM

The way I did this is by using the CanLayout  property of the GraphLayout class. It is protected and only has a get accessor so I overwrote it in my custom graph layout class, so that it returns a settable value:

 

public class PocGraphLayout : GraphLayout<PocVertex, PocEdge, PocGraph>
{
        private bool shouldLayout = true;

        protected override bool CanLayout
        {
            get { return shouldLayout; }
        }

        public bool ShouldLayout
        {
            get { return shouldLayout; }
            set { shouldLayout = value; }
        }

        ......
}

Now I can set the ShouldLayout property to false before I delete an item and the graph won't re-layout. Unfortunately, setting it back to true right after you delete the item will cause it to re-layout anyway. So I had to set it to true at all places that required the graph to re-layout - when you change the layout type, when you load a file, when you create a new graph, when you add new vertices or edges (unless you want it to not re-layout when these are added, in which case you still have to set it to false) and possibly some more place I'm forgetting.

Hope that helps someone.