Intersoft ClientUI Documentation
How-to: Remove The Dragged Object when Dropped to The Drop Target

This example shows how to removed the dragged object when dropped at the drop target.

Example

Description

You can perform a number of tasks during the Drop event. One of the common scenarios is to remove the dragged object from the original source.

The following code shows how to remove the dragged object from original source when dropped at the 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.

Code

XAML
Copy Code
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
    <i:Interaction.Behaviors>
        <Intersoft:DragDropBehavior IsDragable="False" TooltipIcon="NotAllowed.png" TooltipText="Not Allowed"/>
    </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="Remove" TooltipIcon="Remove.png" 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)
{        
    UIElement sourceElement = e.GetSourceElement();
    Panel parent = VisualTreeHelper.GetParent(sourceElement) as Panel;
    parent.Children.Remove(sourceElement);
}
See Also

Concepts

Other Resources