locked
How do you use mousedownevent? RRS feed

  • Question

  • I have a button in my mvvm-light app that is used to show a preview of the changes to an image. I want it to show te preview when you hold the button down and return to the original image when you release the button.

    I know to use a click i just have to bind the command property to a Relaycommand but i dont know how to do it for mousedown and mouseup.

    Tuesday, February 8, 2011 6:10 AM

Answers

  • Hi,

    Below is a sample for button click event for your case.  You can do tiny modifications to achieve your goals.

    http://www.cauldwell.net/patrick/blog/MVVMBindingToCommandsInSilverlight.aspx


    Monday, February 14, 2011 4:00 AM
  • Hi,

    Use behavior look like following code.

    <TextBox x:Name="filterBox" Style="{StaticResource Style_TextBoxTag}" Grid.Column="1">
                         <i:Interaction.Triggers>
                                <i:EventTrigger EventName="TextChanged">
                                    <i:InvokeCommandAction Command="{Binding TextChangedCommand}" CommandParameter="{Binding ElementName=filterBox, Path=Text}"/>
                          </i:EventTrigger>
                         </i:Interaction.Triggers>
                        </TextBox>

    Tuesday, February 15, 2011 2:11 AM
  • I'm assuming you have a ShowPreviewCommand and HidePreviewCommand on your viewmodel?

    You could use TriggerActions to trigger the commands on different events (MouseLeftButton Up/down in sample)

    <Rectangle  Margin="50" Stroke="Black">
    			<i:Interaction.Triggers>
    				<i:EventTrigger EventName="MouseLeftButtonDown">
    					<i:InvokeCommandAction  Command="{Binding ShowPreviewCommand}"/>
    				</i:EventTrigger>
    				<i:EventTrigger EventName="MouseLeftButtonUp">
    					<i:InvokeCommandAction Command="{Binding HidePreviewCommand}"/>
    				</i:EventTrigger>
    			</i:Interaction.Triggers>
    		</Rectangle>


     

    Tuesday, February 15, 2011 3:14 PM

All replies

  • Tuesday, February 8, 2011 6:13 AM
  • Hi,

    Below is a sample for button click event for your case.  You can do tiny modifications to achieve your goals.

    http://www.cauldwell.net/patrick/blog/MVVMBindingToCommandsInSilverlight.aspx


    Monday, February 14, 2011 4:00 AM
  • Hi,

    Use behavior look like following code.

    <TextBox x:Name="filterBox" Style="{StaticResource Style_TextBoxTag}" Grid.Column="1">
                         <i:Interaction.Triggers>
                                <i:EventTrigger EventName="TextChanged">
                                    <i:InvokeCommandAction Command="{Binding TextChangedCommand}" CommandParameter="{Binding ElementName=filterBox, Path=Text}"/>
                          </i:EventTrigger>
                         </i:Interaction.Triggers>
                        </TextBox>

    Tuesday, February 15, 2011 2:11 AM
  • I'm assuming you have a ShowPreviewCommand and HidePreviewCommand on your viewmodel?

    You could use TriggerActions to trigger the commands on different events (MouseLeftButton Up/down in sample)

    <Rectangle  Margin="50" Stroke="Black">
    			<i:Interaction.Triggers>
    				<i:EventTrigger EventName="MouseLeftButtonDown">
    					<i:InvokeCommandAction  Command="{Binding ShowPreviewCommand}"/>
    				</i:EventTrigger>
    				<i:EventTrigger EventName="MouseLeftButtonUp">
    					<i:InvokeCommandAction Command="{Binding HidePreviewCommand}"/>
    				</i:EventTrigger>
    			</i:Interaction.Triggers>
    		</Rectangle>


     

    Tuesday, February 15, 2011 3:14 PM