Vertices Mouse Events

Jun 1, 2009 at 3:43 AM

Hi, 

Is it possible to hook a mouse click (or mouse over) event to vertices, so 'business-load' information associated with a vertex can be displayed on a side panel or some custom action can be performed?

Thanks

 

 

Coordinator
Jun 9, 2009 at 3:00 PM

Yes, you can do it. In the next tutorial i'll show you that.

Aug 21, 2009 at 11:54 AM

Hi palesz,

I want also to know how to manipulate with mouse events on particular edge or vertex.

 

Thanks

Nov 12, 2009 at 11:01 AM
Edited Nov 12, 2009 at 11:14 AM
palesz wrote:

Yes, you can do it. In the next tutorial i'll show you that.

Which tutorial is the best one to look at for this?

EDIT: I just looked for the tutorials and there's only one at present, and although it was last modified just after this discussion originally took place it's not the one that shows how to handle mouse events. Awwww :(

Cheers,

G.

Nov 9, 2010 at 12:34 PM

We are still waiting for your next tutorial ;)

Jan 11, 2011 at 3:21 PM

any update on how to do this?

Oct 18, 2011 at 1:03 PM
Edited Oct 18, 2011 at 1:07 PM
Ok guys, I dont know much about graphsharp, I´m learning along the way... I have found this solution and it works for me:
All that you need is define a style for VertexControl and add an EventSetter for the event you want to raise.

<Style TargetType="{x:Type graphsharp:VertexControl}">
       <EventSetter Event="MouseDoubleClick" Handler="v_MouseDoubleClick"/>
</Style>

And code behind could be like this:
private void v_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{        
   //Do what you need   
   e.Handled = true;
}

I hope it helps.
Oct 19, 2011 at 6:33 AM

Hi dmartel,

first of all I am also learning along the way... but I've done the following. I neded a context menue for each vertex.

In PocVertex class I installed a RoutedCommand

#region VertexContextCommand

        private CommandModel _vertexContextCommand;
        public CommandModel VertexContextCommandModel
        {
            get { return _vertexContextCommand; }
        }

        private class VertexContextCommand : CommandModel
        {

            public VertexContextCommand()
            {
               
            }

            public override void OnQueryEnabled(object sender, CanExecuteRoutedEventArgs e)
            {
                string symbol = e.Parameter as string;

                //e.CanExecute = (!string.IsNullOrEmpty(symbol));
                e.CanExecute = true;
                e.Handled = true;
            }

            public override void OnExecute(object sender, ExecutedRoutedEventArgs e)
            {
                PocVertex pv = e.Parameter as PocVertex;

                if (pv.OnContextClick != null)
                {
                    pv.OnContextClick(pv);
                }

            }

        }

        #endregion


I also installed a ClickHandler (here for a context menue) whicht puts the command through to my VieModel so that I get there
the result at one place with an info about the source vetex. The Handler is installed when each vertex is created, like:

pv.OnContextClick += VertexContextClick;

public delegate void ContextClickHandler(PocVertex p); public event ContextClickHandler OnContextClick; public ContextClickHandler GetOnContextClick() { return OnContextClick; }
Here is the xaml code snippet for that:
<Style TargetType="{x:Type graphsharp:VertexControl}">

                <Setter Property="ContextMenu">
                    <Setter.Value>
                        <ContextMenu >
                           
                            <MenuItem Header="Browser" Command="{Binding VertexContextCommandModel.Command}"
                                    CommandParameter="{Binding myClassAddress}"
                                    local:CreateCommandBinding.Command="{Binding VertexContextCommandModel}"/>
                        </ContextMenu>
                    </Setter.Value>
                </Setter>

and here is the base class for VertexContextCommand, CommandModel.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;

namespace MyApp.Commands
{
    /// <summary>
    /// Model for a command
    /// </summary>
    public abstract class CommandModel
    {
        public CommandModel()
        {
            _routedCommand = new RoutedCommand();
        }

        /// <summary>
        /// Routed command associated with the model.
        /// </summary>
        public RoutedCommand Command
        {
            get { return _routedCommand; }
        }

        /// <summary>
        /// Determines if a command is enabled. Override to provide custom behavior. Do not call the
        /// base version when overriding.
        /// </summary>
        public virtual void OnQueryEnabled(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        /// <summary>
        /// Function to execute the command.
        /// </summary>
        public abstract void OnExecute(object sender, ExecutedRoutedEventArgs e);

        private RoutedCommand _routedCommand;
    }
}

Hope that helps anyhow...

NBT0511