This project has moved. For the latest updates, please go here.

Nicenis has moved to GitHub: https://github.com/Nicenis/Nicenis

Introduction

DropTarget is a static class that provides a little functionalities for a drop target.

Requirements

You have to reference the Nicenis.dll.

Basic Usage

The AllowDrop attached property is required to be set to true. This property also updates the UIElement.AllowDrop property.
  • AllowDrop: Indicating whether the element can be used as the target of a drag-and-drop operation.
This is an example.

<Window x:Class="DropTargetSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:n="clr-namespace:Nicenis.Windows;assembly=Nicenis"
        Title="MainWindow" Height="200" Width="200">

    <!-- This border acts as a drop target.-->
    <Border
        n:DropTarget.AllowDrop="True"
        Margin="30"
        Background="LightGray"
        />
</Window>

You can use the following attached properties to react when a dragged item enters or hovers.
  • IsDragOver: Indicating whether a dragged item is in the drop target.
  • IsDragHover: Indicating whether a dragged item is hovering in the drop target.
The following is an example.

<Window x:Class="DropTargetSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:n="clr-namespace:Nicenis.Windows;assembly=Nicenis"
        Title="MainWindow" Height="200" Width="200">

    <!-- This border acts as a drop target.-->
    <Border n:DropTarget.AllowDrop="True" Margin="30">
        <Border.Style>
            <Style TargetType="Border">
                <Style.Triggers>
                    <!-- If a dragged item is in the drop target. -->
                    <Trigger Property="n:DropTarget.IsDragOver" Value="True">
                        <Setter Property="Background" Value="Green" />
                    </Trigger>

                    <!-- If a dragged item is hovering. -->
                    <Trigger Property="n:DropTarget.IsDragHover" Value="True">
                        <Setter Property="Background" Value="LightGreen" />
                    </Trigger>
                </Style.Triggers>

                <Setter Property="Background" Value="LightGray" />
            </Style>
        </Border.Style>
    </Border>
</Window>

It looks like this image if you hover a dragged item.

Nicenis.Windows.DropTarget Sample Image.png

Download the sample project

Last edited Dec 31, 2016 at 7:16 PM by Ryeol, version 5

Comments

No comments yet.