Intersoft ClientUI Documentation
Drop Event (DropTargetBehavior)



Occurs when drag drop.
Syntax
Public Event Drop As DragEventHandler
Dim instance As DropTargetBehavior
Dim handler As DragEventHandler
 
AddHandler instance.Drop, handler
public event DragEventHandler Drop
public:
event DragEventHandler^ Drop
Event Data

The event handler receives an argument of type DragEventArgs containing data related to this event. The following DragEventArgs properties provide information specific to this event.

PropertyDescription
AllowedEffects Gets allowed effects.
Data Gets data carried.
Effects Gets current drag effects.
Handled (Inherited from Intersoft.Client.Framework.ISRoutedEventArgs) Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.
HandledBy (Inherited from Intersoft.Client.Framework.ISRoutedEventArgs)Gets or sets the source object that handles this event.
IsHandledByPrimitive (Inherited from Intersoft.Client.Framework.ISRoutedEventArgs)Determines whether this event is handled internally by control infrastructure.
KeyStates Gets current key states.
OriginalSource (Inherited from Intersoft.Client.Framework.ISRoutedEventArgs)Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.
RoutedEvent (Inherited from Intersoft.Client.Framework.ISRoutedEventArgs)Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.
Source (Inherited from Intersoft.Client.Framework.ISRoutedEventArgs) Gets or sets a reference to the object that raised the event.
Remarks

This event raised when an object is dropped.

Example

The following code shows how create a copy of dragged object and add it to drop target.

All drag-drop events are built on routed event architecture including the DropEvent. To learn more about routed event, see Routed Events overview.
XAML
Copy Code
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
    <i:Interaction.Behaviors>
        <Intersoft:DragDropBehavior IsDragable="False" DragEffect="Copy"/>
    </i:Interaction.Behaviors>
    <Image Source="folder.png" Height="64" Width="64">
        <i:Interaction.Behaviors>
                <Intersoft:DragDropPointBehavior IsDragable="True"/>
        </i:Interaction.Behaviors>
    </Image>
    <TextBlock Text="My Archive" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Height="100" Width="100" Background="Gray">
    <i:Interaction.Behaviors>
        <Intersoft:DropTargetBehavior TooltipText="Drop here." DropBehavior="Replace"/>
    </i:Interaction.Behaviors>
</Grid>
C#
Copy Code
public MainPage()
{
    // Required to initialize variables
    InitializeComponent();

    ISEventManager.RegisterInstanceHandler(
        this.LayoutRoot, // any element in the routed path which applicable in your scenario
        DragDrop.DropEvent, // the routed event
        new Intersoft.Client.UI.Controls.Interactivity.DragEventHandler(DropTarget_Drop), // the event handler
        true);
}

private void DropTarget_Drop(object sender, Intersoft.Client.UI.Controls.Interactivity.DragEventArgs e)
{
    // get the source object.
    UIElement sourceElement = e.GetSourceElement();
    StackPanel panel = sourceElement as StackPanel;
    Image image = VisualTreeHelper.GetChild(panel, 0) as Image;
    TextBlock text = VisualTreeHelper.GetChild(panel, 1) as TextBlock;

    // create the copy object.
    StackPanel copyPanel = new StackPanel() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
    Image copyImage = new Image() { Source = image.Source, Height = 64, Width = 64 };
    TextBlock copyText = new TextBlock() { Text = text.Text };
    copyPanel.Children.Add(copyImage);
    copyPanel.Children.Add(copyText);
    copyPanel.Opacity = 0; // to make the return animation smooth.

    // register the copy object.
    List<UIElement> elements = new List<UIElement>();
    elements.Add(copyPanel);
    e.SetDropElements(elements); // this method basically set the object that going to be added to the drop target
                                 // since this is copy scenario, we add the copied object, but theoritically you can use any object even multiple objects
}
Requirements

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

See Also

Reference

DropTargetBehavior Class
DropTargetBehavior Members

Concepts

Drag-drop Framework Overview

Send Feedback