Intersoft ClientUI Documentation
DoDragDrop(DependencyObject,Object,DragDropEffects) Method
See Also  Send Feedback
Intersoft.Client.UI.Controls.Interactivity Namespace > ISDragDrop Class : DoDragDrop(DependencyObject,Object,DragDropEffects) Method






dragSource
Object to be dragged.
data
Data carried by the dragged object.
allowedEffects
Allowed drag drop effects.
Perform drag drop operation on specified drag source object.

Syntax

Visual Basic (Declaration) 
Public Shared Function DoDragDrop( _
   ByVal dragSource As DependencyObject, _
   ByVal data As Object, _
   ByVal allowedEffects As DragDropEffects _
) As DragDropEffects
Visual Basic (Usage)Copy Code
Dim dragSource As DependencyObject
Dim data As Object
Dim allowedEffects As DragDropEffects
Dim value As DragDropEffects
 
value = ISDragDrop.DoDragDrop(dragSource, data, allowedEffects)
C# 
public static DragDropEffects DoDragDrop( 
   DependencyObject dragSource,
   object data,
   DragDropEffects allowedEffects
)
Delphi 
public function DoDragDrop( 
    dragSource: DependencyObject;
    data: TObject;
    allowedEffects: DragDropEffects
): DragDropEffects; static; 
JScript 
public static function DoDragDrop( 
   dragSource : DependencyObject,
   data : Object,
   allowedEffects : DragDropEffects
) : DragDropEffects;
Managed Extensions for C++ 
public: static DragDropEffects DoDragDrop( 
   DependencyObject* dragSource,
   Object* data,
   DragDropEffects allowedEffects
) 
C++/CLI 
public:
static DragDropEffects DoDragDrop( 
   DependencyObject^ dragSource,
   Object^ data,
   DragDropEffects allowedEffects
) 

Parameters

dragSource
Object to be dragged.
data
Data carried by the dragged object.
allowedEffects
Allowed drag drop effects.

Return Value

Active drag drop effects.

Example

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

XAML Copy Code
<Grid x:Name="LayoutRoot" Background="White">
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" MouseLeftButtonDown="StackPanel_MouseLeftButtonDown" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp" MouseMove="StackPanel_MouseMove">
        <Image Source="folder.png" Height="64" Width="64"/>
        <TextBlock Text="My Archive" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </StackPanel>
</Grid>
C# Copy Code
private Point _startPosition;
private bool _isMouseLeftDown;        

public MainPage()
{
    // Required to initialize variables
    InitializeComponent();    
}

private void StackPanel_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;

    this._startPosition = e.GetPosition(null, true);
    this._isMouseLeftDown = true;

    element.CaptureMouse();
}

private void StackPanel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;

    this._startPosition = new Point(-1, -1);
    this._isMouseLeftDown = false;

    element.ReleaseMouseCapture();
}

private void StackPanel_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;

    if (this._isMouseLeftDown)
    {
        Point current = e.GetPosition(null, true);

        if (Math.Abs(current.X - this._startPosition.X) >= 4 || Math.Abs(current.Y - this._startPosition.Y) >= 4)
        {
            DragDropEventData dataObject = new DragDropEventData();

            string sourceData = "Some string data to store...";
            byte[] unicodeText = Encoding.Unicode.GetBytes(sourceData); 
            byte[] utf8Text = Encoding.UTF8.GetBytes(sourceData);

            string uniCodeFormat = "Unicode";
            string utf8DataFormat = "UTF-8";
            
            dataObject.SetData(sourceData);            
            dataObject.SetData(uniCodeFormat, unicodeText);            
            dataObject.SetData(utf8DataFormat, utf8Text);

            this._isMouseLeftDown = false;
            DragDrop.DoDragDrop(element, dataObject, DragDropEffects.Move);
        }
    }
}

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. 

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2012 All Rights Reserved.