--- title: "How to: Open a File That is Dropped on a RichTextBox Control" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "drag-and-drop [WPF], RichTextBox" - "RichTextBox [WPF], drag-and-drop" - "drag-and-drop [WPF], open a dropped file" ms.assetid: 6bb8bb54-f576-41db-a9a7-24102ddeb490 --- # How to: Open a File That is Dropped on a RichTextBox Control In Windows Presentation Foundation (WPF), the , , and controls all have built-in drag-and-drop functionality. The built-in functionality enables drag-and-drop of text within and between the controls. However, it does not enable opening a file by dropping the file on the control. These controls also mark the drag-and-drop events as handled. As a result, by default, you cannot add your own event handlers to provide functionality to open dropped files. To add additional handling for drag-and-drop events in these controls, use the method to add your event handlers for the drag-and-drop events. Set the `handledEventsToo` parameter to `true` to have the specified handler be invoked for a routed event that has already been marked as handled by another element along the event route. > [!TIP] > You can replace the built-in drag-and-drop functionality of , , and by handling the preview versions of the drag-and-drop events and marking the preview events as handled. However, this will disable the built-in drag-and-drop functionality, and is not recommended. ## Example The following example demonstrates how to add handlers for the and events on a . This example uses the method and sets the `handledEventsToo` parameter to `true` so that the events handlers will be invoked even though the marks these events as handled. The code in the event handlers adds functionality to open a text file that is dropped on the . To test this example, drag a text file or a rich text format (RTF) file from Windows Explorer to the . The file will be opened in the . If you press the SHIFT key before the dropping the file, the file will be opened as plain text. [!code-xaml[DragDropSnippets#RtbXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/dragdropsnippets/cs/mainwindow.xaml#rtbxaml)] [!code-csharp[DragDropSnippets#RtbHandlers](~/samples/snippets/csharp/VS_Snippets_Wpf/dragdropsnippets/cs/mainwindow.xaml.cs#rtbhandlers)] [!code-vb[DragDropSnippets#RtbHandlers](~/samples/snippets/visualbasic/VS_Snippets_Wpf/dragdropsnippets/vb/mainwindow.xaml.vb#rtbhandlers)]