Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add double click event to a vertex #118

Open
KamilStachera opened this issue Nov 18, 2020 · 2 comments
Open

How to add double click event to a vertex #118

KamilStachera opened this issue Nov 18, 2020 · 2 comments

Comments

@KamilStachera
Copy link

KamilStachera commented Nov 18, 2020

How to add double click event to a vertex (with Dragging set on)

@KamilStachera KamilStachera changed the title How to add onclick effect to a vertex How to add double click event to a vertex Nov 18, 2020
@faint069
Copy link

Hello! Recently I've solved similar problem. I used Devexpress EventToCommand to do this, but I think You can use another binding here.
Here is my XAML code:

 <Style TargetType="{ x:Type controls:VertexControl }">
    ...
    <--<Different setters here/>-->
    ...
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{ x:Type controls:VertexControl }">
            <Grid>
            <dxmvvm:Interaction.Behaviors>
              <dxmvvm:EventToCommand EventName="MouseDown" 
                                     Command="{ Binding SelectCmd}" 
                                     PassEventArgsToCommand="True"
                                     EventArgsConverter="{ StaticResource MouseEventArgsToBoolIsDoubleClick }" />
            </dxmvvm:Interaction.Behaviors>
          ...
         <--Other elements in grid-->
      </Grid>

And here is args converter. It only returns was double click performed or not.

public class MouseEventArgsToBoolIsDoubleClick:IEventArgsConverter 
	{
		public object Convert( object sender, object args )
		{
			if ( args is MouseButtonEventArgs mouseArgs )
			{
				return mouseArgs.ClickCount == 2;
			}

			return false;
		}

In my DataVertex I have command to process doubleclick:

      public ICommand SelectCmd { get; set; }
      //In Constructor:
      SelectCmd = ReactiveCommand.Create<bool>( Select );
    //And Method to be assosiated with command.
    private void Select( bool isDoubleClick )
    {
      if ( isDoubleClick )
      {
        IsSelected = !IsSelected;
      }
    }

Of course You can do all of this simplier, without all this commands and converters.

@bleibold
Copy link
Contributor

bleibold commented Aug 28, 2021

// Assume you have a ZoomControl defined in XAML similar to below:

                  <graphx:ZoomControl x:Name="ErgZoomctrl" Margin="5,0,5,0" Grid.Row="1" Grid.Column="0" 
                                   Grid.ColumnSpan="2" 
                         ViewFinderVisibility="{Binding ViewFinderVisibility}" Background="WhiteSmoke">
                         <models:GraphAreaEx x:Name="ErgArea"/>
                     </graphx:ZoomControl>

// Subscribe to the Event handler.
ErgArea.VertexDoubleClick += ErgArea_OnVertexDoubleClick;

// This event handler is only needed if you need to expose this event for subscribing externally from a UserControl.
public event VertexSelectedEventHandler VertexDoubleClick;

// Add the Event Handler. I use this as another custom User Control so I expose this event to the outside world. You can choose to just respond to the mouse double-click event here as an alternative.

    internal virtual void OnVertexDoubleClick(VertexControl vc, MouseButtonEventArgs e)
    {
      VertexSelectedEventHandler vertexDoubleClick = this.VertexDoubleClick;
      if (vertexDoubleClick == null)
        return;

    //  This handler init is optional.
      vertexDoubleClick((object) this, new VertexSelectedEventArgs(vc, (MouseEventArgs) e, Keyboard.Modifiers));
    }

subscribe to the VertexDoubleClick Event Handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants