Giter Club home page Giter Club logo

Comments (2)

faint069 avatar faint069 commented on August 20, 2024

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.

from graphx.

bleibold avatar bleibold commented on August 20, 2024

// 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

from graphx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.