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?

+2


source to share


4 answers


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>

      

+1


source


Commands are executed using controls such as ToggleButton when clicked. I have no idea about your scenario, but perhaps you can set the IsChecked property to your setter and bind the property to IsChecked. Hope it helps.



0


source


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?

0


source


Commands are not bound, you need to assign a command use command = PushPinMouse

-1


source







All Articles