Question

i'm trying to make a draggable button in blend. using the dragmovebehaviorelement on a button does nothing, and i think this is because a button already uses the LeftMouseButon_down event.

using this behavior on a shape (exp: ellipse) works fine.

is there a way to make a draggable button?

Was it helpful?

Solution

It's not possible to use MouseDragElementBehavior with Button directly because the behavior will never receive the LeftButtonDown event. However, if you are will to change your UI a little, it can be made to work. For example, create a "thumb" that the user can drag to move the button and attach the behavior to the composite object. Here's an example using a little red rectangle to the right of the button:

<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left">
    <i:Interaction.Behaviors>
        <ei:MouseDragElementBehavior/>
    </i:Interaction.Behaviors>
    <Button Content="Button">
    </Button>
    <Rectangle Fill="DarkRed" Width="20"/>
</StackPanel>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top