Positioning new vertex from beginning

Jul 13, 2009 at 4:58 PM

Hey guys!

Im trying to create a funtion where I click with the right button on a blank space of the application and I try to create a new node of the Graph exactly in the point where I clicked, but I dont know how to work with positioning vertex through code. Can anyone give me a hand with that?

Jul 13, 2009 at 9:06 PM

If you have the VertexControl then you just set the GraphLayout.X and GraphLayout.Y attached properties on the VertexControls.

Jul 14, 2009 at 7:38 AM

Im confused... the  VertexControl Class doesnt have any "GraphLayout" or "X" or "Y", property or member. :S

<UserControl x:Class="PFCEditor.Diagram"
             Height="300" Width="300"
    <Grid MouseUp="Grid_MouseUp">
            <graphsharp:GraphLayout x:Name="graphLayout"
                                    Graph="{Binding ElementName=root,Path=GraphToVisualize}"
                <MenuItem Header="Add new state" Click="addNewState_cm"/>

private void addNewState_cm(object sender, RoutedEventArgs e)
      GraphSharp.Controls.VertexControl x = CreateNewVertex();

Jul 15, 2009 at 1:02 PM

using GraphSharp.Controls;

VertexControl vc = graphLayout.GetVertexControl(myVertex);

//setting the mentioned attached properties
GraphCanvas.SetX(vc, the x coordinate);
GraphCanvas.SetY(vc, the y coordinate);

Aug 11, 2009 at 7:15 PM

There's no such thing as ".GetVertexControl" in a GraphLayout object :S

Aug 12, 2009 at 7:44 AM

Are you sure that you have the latest version of the library?

Aug 12, 2009 at 7:50 AM


Aug 22, 2009 at 1:12 PM

I don't think GetVertexControl is in the binary download, but its there if you build from source: http://graphsharp.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Jan 25, 2010 at 3:37 PM
Edited Jan 25, 2010 at 3:37 PM

Hi there.

Even if all this was long ago, I am answering on this discussion since I am experiencing the same problem.

I want to make my own layout, basically if should result in a double tree. Since i have a rather simple graph, this should not be a problem at all.

But I did not make it to change the Vertex position so far. GetVertexControl() is not present, no matter whether I compile graph# on my own or  use the precompiled version from the download section.


Can somebody give some hints on this topic, please?

Oct 20, 2011 at 2:28 PM


same problem here. I know that the topic is pretty old but anyway: Is there any way to get actual positions and set them without GetVertexControl() method, since none is present?

Feb 16, 2012 at 10:29 AM
Edited Feb 16, 2012 at 10:29 AM

Hi guys, i am not an expert, i just have been working with graph# for a while. I am going to explain what works for me.

If you want to set de position of a vertex at the moment that is loaded, you just need to do it on Loaded event, i will show in code.


private void vertex_Loaded(object sender, RoutedEventArgs e)
            VertexControl aux = new VertexControl();
            aux = ((VertexControl)sender);

            double posx, posy;

            posx = "x position of vertex";
            posy = "y position of vertex";

            GraphCanvas.SetX(aux, posx);
            GraphCanvas.SetY(aux, posy);
            e.Handled = true;

I hope it helps.

Apr 6, 2012 at 10:19 AM

hi dmartel, where do yuo declare your event handler? can you post the code?