MainWindow.xaml
<Window x:Class="WPF.DragDropSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WPF="clr-namespace:DotNetBrowser.WPF;assembly=DotNetBrowser" Title="MainWindow" Height="472.343" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="25*"/> <RowDefinition Height="90"/> </Grid.RowDefinitions> <WPF:WPFBrowserView Name="browserView" Grid.Row="0" URL="http://html5demos.com/dnd-upload"/> <TextBox Name="Output" HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Stretch" IsReadOnly="True" AllowDrop="False" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto"/> </Grid> </Window>
C#
MainWindow.xaml.cs
using DotNetBrowser.Events; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WPF.DragDropSample { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); browserView.Browser.DragEnterEvent += Browser_DragEnterEvent; browserView.Browser.DragExitEvent += Browser_DragExitEvent; browserView.Browser.DropEvent += Browser_DropEvent; } private void Browser_DropEvent(object sender, DragDropEventArgs e) { Log("Drop event"); PrintEventDetails(e); } private void Browser_DragExitEvent(object sender, DragDropEventArgs e) { Log("DragExit event"); PrintEventDetails(e); } private void Browser_DragEnterEvent(object sender, DragDropEventArgs e) { Log("DragEnter event"); PrintEventDetails(e); } private void PrintEventDetails(DragDropEventArgs e) { Log("Data type = " + e.DragDropDataType.ToString()); Log("Data: "); foreach (string data in e.Data) { Log(data); } Log(""); } private void Log(string text) { Dispatcher.BeginInvoke(new Action(() => { Output.AppendText(text+"\n"); Output.ScrollToEnd(); })); } } }
VB.NET
MainWindow.xaml.vb
Imports DotNetBrowser.Events Namespace WPF.DragDropSample Public Partial Class MainWindow Inherits Window Public Sub New() InitializeComponent() AddHandler browserView.Browser.DragEnterEvent, AddressOf Browser_DragEnterEvent AddHandler browserView.Browser.DragExitEvent, AddressOf Browser_DragExitEvent AddHandler browserView.Browser.DropEvent, AddressOf Browser_DropEvent End Sub Private Sub Browser_DropEvent(ByVal sender As Object, ByVal e As DragDropEventArgs) Log("Drop event") PrintEventDetails(e) End Sub Private Sub Browser_DragExitEvent(ByVal sender As Object, ByVal e As DragDropEventArgs) Log("DragExit event") PrintEventDetails(e) End Sub Private Sub Browser_DragEnterEvent(ByVal sender As Object, ByVal e As DragDropEventArgs) Log("DragEnter event") PrintEventDetails(e) End Sub Private Sub PrintEventDetails(ByVal e As DragDropEventArgs) Log("Data type = " & e.DragDropDataType.ToString()) Log("Data: ") For Each data As String In e.Data Log(data) Next Log("") End Sub Private Sub Log(ByVal text As String) Dispatcher.BeginInvoke(New Action(Sub() Output.AppendText(text & vbLf) Output.ScrollToEnd() End Sub)) End Sub End Class End Namespace