Intersoft.Client.UI.Controls.Interactivity Namespace > ISDragDrop Class : DoDragDrop(DependencyObject,Object,DragDropEffects) Method |
Public Shared Function DoDragDrop( _ ByVal dragSource As DependencyObject, _ ByVal data As Object, _ ByVal allowedEffects As DragDropEffects _ ) As DragDropEffects
Dim dragSource As DependencyObject Dim data As Object Dim allowedEffects As DragDropEffects Dim value As DragDropEffects value = ISDragDrop.DoDragDrop(dragSource, data, allowedEffects)
public static DragDropEffects DoDragDrop( DependencyObject dragSource, object data, DragDropEffects allowedEffects )
public: static DragDropEffects DoDragDrop( DependencyObject^ dragSource, Object^ data, DragDropEffects allowedEffects )
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.
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); } } } |
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2