Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Command for Button, check if right clicked

Command for Button, check if right clicked

Scheduled Pinned Locked Moved WPF
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ezazazel
    wrote on last edited by
    #1

    Hi guys! Is there a chance to find out, whether a button was right or left clicked by using commands? What I would like to do is add to commands to a button, one for left click and one for right click. Thanks in advance!

    A G 2 Replies Last reply
    0
    • E ezazazel

      Hi guys! Is there a chance to find out, whether a button was right or left clicked by using commands? What I would like to do is add to commands to a button, one for left click and one for right click. Thanks in advance!

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      You can add a MouseBinding(or MouseGesture). Something like this,

      <MouseBinding Gesture="LeftClick"
      Command="ApplicationCommands.Open" />

      MouseBinding needs the Mouse action and the routed command to be executed. You will have to add another MouseBinding for Right-click and also change the Command value to the routed command to be executed in your case. For more details, see here[^], here[^] and here[^]

      E 1 Reply Last reply
      0
      • E ezazazel

        Hi guys! Is there a chance to find out, whether a button was right or left clicked by using commands? What I would like to do is add to commands to a button, one for left click and one for right click. Thanks in advance!

        G Offline
        G Offline
        Gideon Engelberth
        wrote on last edited by
        #3

        I have done something like that before. I put it in a custom control since the basic button class does not seem to provide such functionality. Hmmmm... sounds like an article that should be written...

        A 1 Reply Last reply
        0
        • G Gideon Engelberth

          I have done something like that before. I put it in a custom control since the basic button class does not seem to provide such functionality. Hmmmm... sounds like an article that should be written...

          A Offline
          A Offline
          ABitSmart
          wrote on last edited by
          #4

          You can do it with a MouseBinding. Did you see my suggestion[^] ?

          G 1 Reply Last reply
          0
          • A ABitSmart

            You can do it with a MouseBinding. Did you see my suggestion[^] ?

            G Offline
            G Offline
            Gideon Engelberth
            wrote on last edited by
            #5

            I did not see your reply until after I posted mine (nor did I consider the possibility of putting input bindings on individual controls instead of the window). Since I already have a solution working, I think I will stick with it. Plus, I prefer to write this:

            <TextBlock controls:DualCommandProvider.LeftClickCommand="Open"
            controls:DualCommandProvider.RightClickCommand="Close" />

            instead of this:

            <TextBlock>
            <TextBlock.InputBindings>
            <MouseBinding Command="Open" MouseAction="LeftClick" />
            <MouseBinding Command="Close" MouseAction="RightClick" />
            </TextBlock.InputBindings>
            </TextBlock>

            Especially since where I am using this, I am putting left and right click actions on many controls and the extra lines would make the flow of the design harder to follow.

            A 1 Reply Last reply
            0
            • G Gideon Engelberth

              I did not see your reply until after I posted mine (nor did I consider the possibility of putting input bindings on individual controls instead of the window). Since I already have a solution working, I think I will stick with it. Plus, I prefer to write this:

              <TextBlock controls:DualCommandProvider.LeftClickCommand="Open"
              controls:DualCommandProvider.RightClickCommand="Close" />

              instead of this:

              <TextBlock>
              <TextBlock.InputBindings>
              <MouseBinding Command="Open" MouseAction="LeftClick" />
              <MouseBinding Command="Close" MouseAction="RightClick" />
              </TextBlock.InputBindings>
              </TextBlock>

              Especially since where I am using this, I am putting left and right click actions on many controls and the extra lines would make the flow of the design harder to follow.

              A Offline
              A Offline
              ABitSmart
              wrote on last edited by
              #6

              I have a different opinion though. I feel separating it into a different section would make it easier to follow. It would demarcate the properties and bindings into separate group instead of all of them being together. It looks neat with just two entries but I would go crazy when the properties/bindings set through XAML would increase and make the node look ugly. This method has the obvious advantages of inherent implementation and access to all Mouse gestures in addition to the left and right click. But hey, as you feel comfortable. Cheers :)

              1 Reply Last reply
              0
              • A ABitSmart

                You can add a MouseBinding(or MouseGesture). Something like this,

                <MouseBinding Gesture="LeftClick"
                Command="ApplicationCommands.Open" />

                MouseBinding needs the Mouse action and the routed command to be executed. You will have to add another MouseBinding for Right-click and also change the Command value to the routed command to be executed in your case. For more details, see here[^], here[^] and here[^]

                E Offline
                E Offline
                ezazazel
                wrote on last edited by
                #7

                Thanks for your solution

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups