How to use the DragMoveBehaviorElement (drag) on a button in blend?

£可爱£侵袭症+ 提交于 2019-12-11 07:14:30

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/4599629/how-to-use-the-dragmovebehaviorelement-drag-on-a-button-in-blend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!