XAML Setter Property for Command
I am trying to invoke 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 reel in the mouse, the hand shows. But when I drop my mouse pointer, it doesn't hit my PushPinMouse method. Why?
This is where you need to attach the behavior. I can recommend this nice article for you: http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/04/14/wpf-commands-everywhere.aspx
Your code will look like (using Attached Commands library):
<Style>
<Setter Property="ts:CommandSource.Trigger">
<Setter.Value>
<ts:PropertyCommandTrigger Property="IsMouseOver" Value="true" Command="{Binding Path=PushPinMouse}"/>
</Setter.Value>
</Setter>
</Style>
It says, "When the mouse is over, execute the PushPinMouse command." If this is not the behavior you want, perhaps you can adapt this code;) Like everyone else, the button command only fires when pressed, but this library can add commands to other events (whereas routed events or events with changed properties ).
You will need this trigger anyway:
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"></Setter>
</Trigger>
source to share
You change the command that the button starts, but it doesn't actually execute the button until you press it. So in this case, you will need to hover over and click to execute the command.
I also assume that you have bound your command to a command function using the CommandBinding?
source to share