Partilhar via


MouseDragElementBehavior

You can easily add the functionality of dragging an item around on a Windows Phone screen to an element by adding a MouseDragElementBehavior behavior.

Note

The MouseDragElementBehavior behavior doesn't work for any controls that handle MouseClick events (Button, TextBox, and ListBox controls, for example). If you require the ability to drag a control of one of these types, make that control a child of a control that can be dragged (a border, for example). You can then apply the MouseDragElementBehavior behavior to the parent element.

To add a MouseDragElementBehavior to a Windows Phone project

  1. In the Assets panel, click Behaviors, and then drag MouseDragElementBehavior onto the artboard and drop it onto the object that you have created. The Common Properties category appears in the Properties panel.

    Note

    The object to which the behavior is added provides the context within which the behavior operates.

  2. In the Common Properties category, select or clear the ConstrainToParentBounds property. When selected, the ConstrainToParentBounds property restricts the element from being dragged outside the boundaries specified by the parent layout container.

    In addition to ConstrainToParentBounds, two other advanced properties are exposed. These properties can be used (by using data binding, for example) to display the current X and Y coordinates of the element being dragged.

    MouseDragElementBehavior

To see a sample of this behavior, visit the Expression Community Gallery Ff979332.xtlink_newWindow(en-us,Expression.40).png.

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.