Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5948249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:04:50+00:00 2026-05-22T17:04:50+00:00

Hi i have recently looked into WPF and started learning about Events and Commands.

  • 0

Hi i have recently looked into WPF and started learning about Events and Commands. I typically use Commands on Button clicks which causes a method to Run in my “view model”.

Is it possible to make the Button react to any other events like the MouseOver event through the use of commnds? Or would WPF Events be used in this case?

If WPF Events are to be used, then should the event handler implementation just call a method in the View Model to keep concerns sperate?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:04:51+00:00Added an answer on May 22, 2026 at 5:04 pm

    This is a fair question, and one that is a common, yet “solved” (debatably) problem within the MVVM architecture realm. If you are using an MVVM framework, you are likely to find something similar to the EventToCommand Behavior, here is the sample from the MVVM Light Toolkit.

    In short, this allows you to map an event to a command binding like so:

    <Rectangle Fill="White"
           Stroke="Black"
           Width="200"
           Height="100">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <cmd:EventToCommand Command="{Binding TestCommand,
                                          Mode=OneWay}"
               CommandParameter="{Binding Text,
                                  ElementName=MyTextBox,
                                  Mode=OneWay}"
               MustToggleIsEnabledValue="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    </Rectangle>
    

    Update:

    There are two other “reasonable” solutions to this problem:

    One uses the now considered legacy “AttachedCommandBehavior” extension found here.

    The other is a little bit irritating, but workable.

    1. Capture a command via en
      event purely in the view.
    2. Query the control’s DataSource Step
    3. Grab a string binding target
      identifier that denotes your command
      (perhaps using a const string on the
      view)
    4. Invoke your command on
      the view model via reflection and
      pass in the command arguments.

    This looks gross but I’m fairly certain is actually a bit faster than just using traditional command
    bindings. In order to be sure I’d need to see the IL, and I don’t think that it matters in this case.

    /Update

    I want to note however that this is not always an ideal situation. I’ve discovered that more often than not, I’m using EventToCommand to cover a design issue. Please consider the following:

    • Use events and code behind to handle User-Interface related behaviors.
    • Consider creating custom controls that have command bindings if appropriate, especially if you find yourself using commands to encapsulate event driven bevahior to set bound data that is then reflected in the view. (i.e. setting a transparency value based on proximity to a control or something similar)
    • EventToCommand should most likely be used to handle “Command-like” events only (double clicking etc) not reactive events (mouse-over). However there is nothing preventing this. Implement as you see fit.

    Most importantly perhaps is that you remember that you are the developer. Guidelines in themselves do not solve problems, but consideration of guidelines may make the solution to a problem apparent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked a little bit into face recognition recently. However I am overwelmed
I have recently looked into this and discovered that using FBML pages in a
I've been a web developer for some time now, and have recently started learning
I have looked into Ajax only recently (laugh at me you experts), and I
I have recently found myself becoming more negative about EF and cannot help wondering
I have recently started seeing user agents like Java/1.6.0_14 (and variations) on my site
I have recently started using DocCheck for checking the validity of JavaDoc's in code
I have recently run into a particularly sticky issue regarding committing the result of
I have recently become interested in the field(s) of data mining and machine learning.
I have recently started to learn Objective-C and write my tests using OCUnit that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.