# Enable Only Drop Inside

This tutorial demonstrates how to enable dropping inside the **RadTreeViewItems**, but not around them.

For the purpose of this tutorial will be used the following treeview declaration:

```XAML
<UserControl>
    <UserControl.Resources>
        <sampleData:RadTreeViewSampleData x:Key="DataSource"/>
        <DataTemplate x:Key="Team">
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>

        <HierarchicalDataTemplate x:Key="Division"
	        ItemsSource="{Binding Teams}"
	        ItemTemplate="{StaticResource Team}">
            <TextBlock Text="{Binding Name}"/>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate x:Key="League" 
	        ItemsSource="{Binding Divisions}"
	        ItemTemplate="{StaticResource Division}">
            <TextBlock Text="{Binding Name}"/>
        </HierarchicalDataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadTreeView x:Name="radTreeView" IsDragDropEnabled="True" Margin="8"
	        ItemsSource="{Binding Source={StaticResource DataSource}, Path=LeaguesDataSource}"
	        ItemTemplate="{StaticResource League}"/>
    </Grid>
</UserControl>
```

> tip The **RadTreeView** is data bound to a collection of business objects. For more information, read the [Binding to Object](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/populating-with-data/data-binding-to-object) topic.

In order to implement only drop inside you need to perform the following steps:

* Attach to the **DragDropManager DragOver** event:

  ```C#
  DragDropManager.AddDragOverHandler(xTreeView, OnDragOver, true);
  ```

  ```VB.NET
  		DragDropManager.AddDragOverHandler(xTreeView, OnDragOver, True)
  ```

  > tip **RadTreeView** handles internally the **DragDropManager** events and in order to invoke a custom handler, you need to explicitly specify that you're adding a handler that should be invoked even for already handled events. This is done through the last - **bool** argument of the **DragDropManager.AddDragOverHandler** extension method.

* In the event handler you should use the following code:

  ```C#
  private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
  {
      var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
      if (options != null && options.DropPosition != Telerik.Windows.Controls.DropPosition.Inside)
      {
          options.DropPosition = Telerik.Windows.Controls.DropPosition.Inside;
          options.UpdateDragVisual();
      }
  }
  ```

  ```VB.NET
  		Private Sub OnDragOver(sender As Object, e As Telerik.Windows.DragDrop.DragEventArgs)
  			Dim options = TryCast(DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key), TreeViewDragDropOptions)
  			If options IsNot Nothing AndAlso options.DropPosition <> Telerik.Windows.Controls.DropPosition.Inside Then
  				options.DropPosition = Telerik.Windows.Controls.DropPosition.Inside
  				options.UpdateDragVisual()
  			End If
  		End Sub
  ```

  Please note that if you want the changes applied on the **TreeViewDragDropOptions** object to affect the **DragVisual** element, you have to invoke the **UpdateDragVisual()** method.

> tip Find a runnable project of the previous example in the [WPF Samples GitHub repository](https://github.com/telerik/xaml-sdk/tree/master/TreeView/EnableOnlyDropInsideItem).

## See Also

* [Drag and Drop](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/features/dragdrop/drag-and-drop)
* [Implement Drag and Drop Between TreeView and ListBox](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/how-to/drag-and-drop/implement-between-treeview-and-listbox)
* [Disable Drop at Specific Location](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/how-to/drag-and-drop/disable-drop-specific-location)
* [Implement Copy Drag](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/how-to/drag-and-drop/implement-copy-drag)
* [Auto Expand on Drag Over](https://www.telerik.com/products/wpf/documentation/controls/radtreeview/how-to/drag-and-drop/enable-auto-expand-drag-over)
