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. Binding Commands to Events?

Binding Commands to Events?

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfregexarchitecture
8 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.
  • S Offline
    S Offline
    Steve The Plant
    wrote on last edited by
    #1

    Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!

    P S N 3 Replies Last reply
    0
    • S Steve The Plant

      Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      These events are, strictly speaking, view only events, so why would you want them to be handled in the VM? There's no rule that says you can't have code behind the view, so if you need to do things, you can do it there. What are you trying to do that goes beyond the V/VM separation?

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      S 1 Reply Last reply
      0
      • P Pete OHanlon

        These events are, strictly speaking, view only events, so why would you want them to be handled in the VM? There's no rule that says you can't have code behind the view, so if you need to do things, you can do it there. What are you trying to do that goes beyond the V/VM separation?

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        S Offline
        S Offline
        Steve The Plant
        wrote on last edited by
        #3

        Hi Pete, Those events were just examples. It can be any type of event that I might need to handle. In our application we can change XAML files dynamically, so we're trying to avoid solutions that involve code-behind files. Thanks!

        1 Reply Last reply
        0
        • S Steve The Plant

          Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!

          S Offline
          S Offline
          Steve The Plant
          wrote on last edited by
          #4

          I haven't tried it yet, but this answer looks promising. http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0cb73e76-b7dd-4a47-af27-cd05da2f305e[^]

          P 1 Reply Last reply
          0
          • S Steve The Plant

            I haven't tried it yet, but this answer looks promising. http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0cb73e76-b7dd-4a47-af27-cd05da2f305e[^]

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Attached behaviours are a good way to go - and one I'm particularly fond of (see this[^] blog post for an example).

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            N 1 Reply Last reply
            0
            • P Pete OHanlon

              Attached behaviours are a good way to go - and one I'm particularly fond of (see this[^] blog post for an example).

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              N Offline
              N Offline
              Niladri_Biswas
              wrote on last edited by
              #6

              I don't know your actual requirement but ICommand can be helpful in such situations. It makes your view cleaner. May I get the exact scenario for the problem? :)

              Niladri Biswas

              modified on Thursday, June 4, 2009 10:32 AM

              P 1 Reply Last reply
              0
              • N Niladri_Biswas

                I don't know your actual requirement but ICommand can be helpful in such situations. It makes your view cleaner. May I get the exact scenario for the problem? :)

                Niladri Biswas

                modified on Thursday, June 4, 2009 10:32 AM

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                I suspect you meant to raise this against the OP, not me. He won't be notified of posts against my account, so could you reply to him instead.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • S Steve The Plant

                  Hi, What's a good method to bind Commands to Events? In my WPF app, there are events that I'd like to capture and process by my ViewModel but I'm not sure how. Things like losing focus, mouseover, mousemove, etc. Since I'm trying to adhere to the MVVM pattern, I'm wondering if there's a XAML solution for that. Thanks!

                  N Offline
                  N Offline
                  Niladri_Biswas
                  wrote on last edited by
                  #8

                  I don't know your actual requirement but ICommand can be helpful in such situations. It makes your view cleaner. May I get the exact scenario for the problem? :)

                  Niladri Biswas

                  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