tags:

views:

60

answers:

2

I am trying to call a command when my mouse is over a toggle button.

I have the following code.

<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"></Setter>
<Setter Property="Command" Value="{Binding Path=PushPinMouse}" />
</Trigger>

When I roll the mouse over, the hand shows. But when i roll the mouse over it doesn't hit my PushPinMouse method.. Why's that?

A: 

Setting Command property of the button is not supposed to trigger a command. It's supposed to specify a command that will be triggered when the button is clicked. MSDN says so right away:

Gets or sets the command to invoke when this button is pressed.

Pavel Minaev
is there an Idea that I can call an command when the mouse hovers over?
A: 

There is no direct way to do this. A common pattern is to make an attached behavior which will listen to the event in question, and fire an event.

A good, simple implementation is demonstrated in this CodeProject arcticle on the Cinch Framwork. Look for the LifetimeEvent class implementation. This provides an attached behavior which subscribes to the "Activated" event on a form. You can just as easily make one that listens for IsMouseOver changes, and fires a command.

If you wrote that, you could then do:

<Button local:HoverBehavior.Hovering="{Binding MyCommand}" />

You could use the Behavior<T> class in the Expression Blend SDK to implement this in a simpler manner, as well.

Reed Copsey