Skip to end of metadata
Go to start of metadata

Provides drag drop capability to UIElement.

Working with AllowDropProperty Field

To make an UIElement droppable, you can choose one of the following approaches:

  • Attach a DropTargetBehavior
  • Set the ISDragDrop.AllowDrop attached property to True
  • Set the AllowDrop property to  True

AllowDrop property is only available in SL4 and WPF.
This approach is only used to mark the UIElement as a droppable element. It does not include built-in handling such as in DropTargetBehavior thus requires you to write additional logic at the Drop event. To learn how to handle Drop event, see How to: Copy the dragged object when dropped to the drop target and How to: Remove the drag object when dropped to drop target.
Since Silverlight 3 does not have AllowDrop property in UIElement, the ISDragDrop.AllowDrop attached property is introduced to maintain code compatibility across Silverlight 3, Silverlight 4 and WPF.

Working with AllowGridDropProperty Field

Often times, you may want to restrict objects from being dropped next to certain items in the UXGridPanel. The following code shows how to prevent drop using ISDragDrop.AllowGridDrop property.

XAML

Working with AllowNextDropProperty Field and AllowPreviousDropProperty Field

By default, when you enable the AllowReorderItem or AllowDropItem property in an UXPanel, all children elements in the panel will be queried to accept the dragged object. A children element will show an empty space in its left or the right position which indicates that the element can accept the dragged object to drop into the provided empty space.

In certain scenarios, you may want to restrict the dragged object from being dropped to the left or right side of a certain element in the panel.

The following code shows how to prevent drop using the ISDragDrop.AllowNextDrop and ISDragDrop.AllowPreviousDrop attached property.

XAML

In the above illustration, the green rectangle is moved to the area between the red and the yellow rectangle. Since the red rectangle has the ISDragDrop.AllowNextDrop set to False, the green rectangle can not be dropped in the area between the read and the yellow rectangle. Notice that the animation that opens the empty space will not be performed in this case.

Working with IsDragScopeProperty Field

ClientUI provides a comprehensive drag-drop framework that enables you to easily create fluid drag and drop user experiences. When an object is being dragged, the drag-drop framework detects the available drop target within a certain scope which is determined by the DragDropScope property. The default value for this property is Global which means that the scope is set to the root visual of your application. In this case, the drag-drop framework will search for any droppable controls available in your application.

In certain scenarios, you might want to limit the scope of the drag drop operation. This can be done by changing the DragDropScope property to Parent, then apply the ISDragDrop.IsDragDropScope attached property to the element which the drag-drop operation should be scoped.

To understand about the drag-drop scope capability, consider the following scenario.

XAML

In this scenario, the dragable element is set to My Archive object while the droppable targets are set to the GreenContainer, the RedContainer, the SiblingContainer and the SourceContainer.

If the DragDropScope property is set to Global, the objects can be dragged and dropped into any of the drop targets. You can limit the drag-drop scope by setting the DragDropScope property to Parent and determine the drag-drop scope by using the ISDragDrop.IsDragDropScope attached property. See the following example.

XAML

With this configuration you are able to drag the My Archive object to SiblingContainer but not to RedContainer or GreenContainer.

Working with ShadowInitEvent Field

The following example code demonstrates how to create custom object / image and uses it as drag shadow object when drag drop take place.

XAML
C#

Working with DoDragDrop(DependencyObject,Object,DragDropEffects) Method

This example show you how to make an UIElement dragable and how to store the data to be carried.

XAML
C#

Definition

public static class ISDragDrop

Summary

The following table summarizes the members exposed in this class.

Fields

AllowDragPropertyIdentifies the AllowDrag dependency property.
AllowDropObjectPropertyIdentifies the AllowDropObject dependency property.
AllowDropPropertyIdentifies the AllowDrop dependency property.
AllowGridDropPropertyIdentifies the AllowGridDrop dependency property.
AllowMovePropertyIdentifies the AllowMove dependency property.
AllowNextDropPropertyIdentifies the AllowNextDrop dependency property.
AllowPreviousDropPropertyIdentifies the AllowPreviousDrop dependency property.
AllowRemovePropertyIdentifies the AllowRemove dependency property.
AllowReorderPropertyIdentifies the AllowReorder dependency property.
DragEndedEventIdentifies the DragEnded routed event.
DragEndEventIdentifies the DragEnd routed event.
DragInitEventIdentifies the DragInit routed event.
DragReturnedEventIdentifies the DragReturned routed event.
DragReturnEventIdentifies the DragReturn routed event.
DragSourceEventIdentifies the DragSource routed event.
DragStartedEventIdentifies the DragStarted routed event.
DragStartEventIdentifies the DragStart routed event.
DropObjectChangedEventIdentifies the DropObjectChanged routed event.
DropObjectCommandPropertyIdentifies the DropObjectCommand dependency property.
IsDragScopePropertyIdentifies the IsDragScope dependency property.
PrepareDropEventIdentifies the PrepareDrop routed event.
PreviewQueryDropStateEventIdentifies the PreviewQueryDropState routed event.
QueryDropStateEventIdentifies the QueryDropState routed event.
ShadowCreatedEventIdentifies the ShadowCreated routed event.
ShadowInitEventIdentifies the ShadowInit routed event.

Static Methods

DoDragDrop(DependencyObject, object, DragDropEffects)Perform drag drop operation on specified drag source object.
GetAllowDrag(UIElement)Gets allow drag value from target element.
GetAllowDrop(UIElement)Gets allow drop value from target element.
GetAllowDropObject(UIElement)Gets allow drop object value from target element.
GetAllowGridDrop(UIElement)Gets allow grid drop value from target element.
GetAllowMove(UIElement)Gets allow move value from target element.
GetAllowNextDrop(UIElement)Gets allow next value from target element.
GetAllowPreviousDrop(UIElement)Gets allow previous value from target element.
GetAllowRemove(UIElement)Gets allow remove value from target element.
GetAllowReorder(UIElement)Gets allow reorder value from target element.
GetDropObjectCommand(UIElement)Gets command that will be raised when dropping object to element.
GetIsDragScope(UIElement)Gets IsDragScope value from target element.
SetAllowDrag(UIElement, bool)Sets allow drag value to target element.
SetAllowDrop(UIElement, bool)Sets allow drop value to target element.
SetAllowDropObject(UIElement, bool)Sets allow drop object value to target element.
SetAllowGridDrop(UIElement, bool)Sets allow grid drop value to target element.
SetAllowMove(UIElement, bool)Sets allow move value to target element.
SetAllowNextDrop(UIElement, bool)Sets allow next value to target element.
SetAllowPreviousDrop(UIElement, bool)Sets allow previous value to target element.
SetAllowRemove(UIElement, bool)Sets allow remove value to target element.
SetAllowReorder(UIElement, bool)Sets allow reorder value to target element.
SetDropObjectCommand(UIElement, ICommand)Sets command that will be raised when dropping object to target element.
SetIsDragScope(UIElement, bool)Sets IsDragScope value to target element.

Fields

public static readonly DependencyProperty AllowDragProperty

Identifies the AllowDrag dependency property.

public static readonly DependencyProperty AllowDropObjectProperty

Identifies the AllowDropObject dependency property.

public static readonly DependencyProperty AllowDropProperty

Identifies the AllowDrop dependency property.

public static readonly DependencyProperty AllowGridDropProperty

Identifies the AllowGridDrop dependency property.

public static readonly DependencyProperty AllowMoveProperty

Identifies the AllowMove dependency property.

public static readonly DependencyProperty AllowNextDropProperty

Identifies the AllowNextDrop dependency property.

public static readonly DependencyProperty AllowPreviousDropProperty

Identifies the AllowPreviousDrop dependency property.

public static readonly DependencyProperty AllowRemoveProperty

Identifies the AllowRemove dependency property.

public static readonly DependencyProperty AllowReorderProperty

Identifies the AllowReorder dependency property.

public static readonly RoutedEvent DragEndedEvent

Identifies the DragEnded routed event.

public static readonly RoutedEvent DragEndEvent

Identifies the DragEnd routed event.

public static readonly RoutedEvent DragInitEvent

Identifies the DragInit routed event.

public static readonly RoutedEvent DragReturnedEvent

Identifies the DragReturned routed event.

public static readonly RoutedEvent DragReturnEvent

Identifies the DragReturn routed event.

public static readonly RoutedEvent DragSourceEvent

Identifies the DragSource routed event.

public static readonly RoutedEvent DragStartedEvent

Identifies the DragStarted routed event.

public static readonly RoutedEvent DragStartEvent

Identifies the DragStart routed event.

public static readonly RoutedEvent DropObjectChangedEvent

Identifies the DropObjectChanged routed event.

public static readonly DependencyProperty DropObjectCommandProperty

Identifies the DropObjectCommand dependency property.

public static readonly DependencyProperty IsDragScopeProperty

Identifies the IsDragScope dependency property.

public static readonly RoutedEvent PrepareDropEvent

Identifies the PrepareDrop routed event.

public static readonly RoutedEvent PreviewQueryDropStateEvent

Identifies the PreviewQueryDropState routed event.

public static readonly RoutedEvent QueryDropStateEvent

Identifies the QueryDropState routed event.

public static readonly RoutedEvent ShadowCreatedEvent

Identifies the ShadowCreated routed event.

public static readonly RoutedEvent ShadowInitEvent

Identifies the ShadowInit routed event.

Remarks

This event raised when shadow image is being initialized. You can customize the drag shadow object from this event.

 

Static Methods

public static DragDropEffects DoDragDrop(DependencyObject dragSource, object data, DragDropEffects allowedEffects)

Perform drag drop operation on specified drag source object.

Remarks

To make an UIElement dragable, you can also use the provided API. The API to drag the object is DragDrop.DoDragDrop method. You can also use the ISDragDrop.DoDragDrop method, since this method is equivalent with DragDrop.DoDragDrop method. The DragDrop.DoDragDrop is provided to enable unified shared code base with WPF, allowing you to easily migrate your existing WPF application that used WPF's Drag-drop API to the Silverlight application without major changes.

Parameters

dragSourceObject to be dragged.
dataData carried by the dragged object.
allowedEffectsAllowed drag drop effects.

Return Types

Active drag drop effects.

 

public static bool GetAllowDrag(UIElement element)

Gets allow drag value from target element.

Parameters

elementTarget element.

Return Types

Allow drag.

 

public static bool GetAllowDrop(UIElement element)

Gets allow drop value from target element.

Parameters

elementTarget element.

Return Types

Allow drop.

 

public static bool GetAllowDropObject(UIElement element)

Gets allow drop object value from target element.

Parameters

elementTarget element.

Return Types

Allow drop object.

 

public static bool GetAllowGridDrop(UIElement element)

Gets allow grid drop value from target element.

Parameters

elementTarget element.

Return Types

Allow drop.

 

public static bool GetAllowMove(UIElement element)

Gets allow move value from target element.

Parameters

elementTarget element.

Return Types

Allow move.

 

public static bool GetAllowNextDrop(UIElement element)

Gets allow next value from target element.

Parameters

elementTarget element.

Return Types

Allow next.

 

public static bool GetAllowPreviousDrop(UIElement element)

Gets allow previous value from target element.

Parameters

elementTarget element.

Return Types

Allow previous.

 

public static bool GetAllowRemove(UIElement element)

Gets allow remove value from target element.

Parameters

elementTarget element.

Return Types

Allow remove.

 

public static bool GetAllowReorder(UIElement element)

Gets allow reorder value from target element.

Parameters

elementTarget element.

Return Types

Allow reorder.

 

public static ICommand GetDropObjectCommand(UIElement element)

Gets command that will be raised when dropping object to element.

Parameters

elementTarget element.

Return Types

Drop object command.

 

public static bool GetIsDragScope(UIElement element)

Gets IsDragScope value from target element.

Parameters

elementTarget element.

Return Types

IsDragScope.

 

public static void SetAllowDrag(UIElement element, bool value)

Sets allow drag value to target element.

Parameters

elementTarget element.
valueAllow drag.

 

public static void SetAllowDrop(UIElement element, bool value)

Sets allow drop value to target element.

Parameters

elementTarget element.
valueAllow drop.

 

public static void SetAllowDropObject(UIElement element, bool value)

Sets allow drop object value to target element.

Parameters

elementTarget element.
valueAllow drop object.

 

public static void SetAllowGridDrop(UIElement element, bool value)

Sets allow grid drop value to target element.

Parameters

elementTarget element.
valueAllow drop.

 

public static void SetAllowMove(UIElement element, bool value)

Sets allow move value to target element.

Parameters

elementTarget element.
valueAllow move.

 

public static void SetAllowNextDrop(UIElement element, bool value)

Sets allow next value to target element.

Parameters

elementTarget element.
valueAllow next.

 

public static void SetAllowPreviousDrop(UIElement element, bool value)

Sets allow previous value to target element.

Parameters

elementTarget element.
valueAllow previous.

 

public static void SetAllowRemove(UIElement element, bool value)

Sets allow remove value to target element.

Parameters

elementTarget element.
valueAllow remove.

 

public static void SetAllowReorder(UIElement element, bool value)

Sets allow reorder value to target element.

Parameters

elementTarget element.
valueAllow reorder.

 

public static void SetDropObjectCommand(UIElement element, ICommand value)

Sets command that will be raised when dropping object to target element.

Parameters

elementTarget element.
valueDrop object commandr.

 

public static void SetIsDragScope(UIElement element, bool value)

Sets IsDragScope value to target element.

Parameters

elementTarget element.
valueIsDragScope.
  • No labels