How to add Double Click event on Vertex?

Apr 20, 2011 at 7:33 PM

Hi everyone

       Do you have any idea about how to add "Double Click" event on each Vertex?

       Thanks for help.

Apr 20, 2011 at 10:19 PM

I figured it out.

in Graph Loaded event, add MouseDoubleClick on each VertexControl in a loop. Something like this:

foreach (var v in graphLayout.Children)
            {
                if(v is VertexControl)
                 (v as VertexControl).MouseDoubleClick += new MouseButtonEventHandler(v_MouseDoubleClick);
            }

Coordinator
Apr 21, 2011 at 9:22 AM

This is a solution, but another solution could be:

Create a new ControlTemplate for your VertexControl (or a DataTemplate for your Vertex type) and put this event handler binding into that xaml.

Aug 2, 2011 at 4:01 PM

The predecessor of EdgeControl supports 'MouseButtonEventHandler MouseDoubleClick' can you show how to bind that handler to a view model?

Feb 2, 2013 at 12:00 PM
where did you define the Graph Loaded event?
I found a way to define it only in the graphlayout xaml tag and I can't get to vertex control from it
Feb 2, 2013 at 12:01 PM
Troy96 wrote:
I figured it out. in Graph Loaded event, add MouseDoubleClick on each VertexControl in a loop. Something like this: foreach (var v in graphLayout.Children)            {                if(v is VertexControl)                 (v as VertexControl).MouseDoubleClick += new MouseButtonEventHandler(v_MouseDoubleClick);            }
where did you define the Graph Loaded event?
I found a way to define it only in the graphlayout xaml tag and I can't get to vertex control from it
Mar 13, 2013 at 6:34 PM
In VertexControl.cs
        public VertexControl()
        {
            MouseDoubleClick += VertexControl_MouseDoubleClick;
        }

        void VertexControl_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            RootCanvas.OnVertexSelected(this);
        }
In GraphCanvas.cs add:
        public virtual event VertexSelectedEventHandler VertexSelected;

        public virtual void OnVertexSelected(VertexControl vc)
        {
            if (VertexSelected != null)
                VertexSelected(this, new VertexSelectedEventArgs(vc));
        }
In any new code file add:
    public delegate void VertexSelectedEventHandler(object sender, VertexSelectedEventArgs args);

    public class VertexSelectedEventArgs : System.EventArgs
    {
        public VertexControl VertexControl { get; set; }

        public VertexSelectedEventArgs(VertexControl vc)
            : base()
        {
            VertexControl = vc;
        }
    }
Now you can bind to GraphCanvas (or GraphLayout) event: VertexSelected and get the VertexControl you double clicked on.