-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMainWindow.xaml.vb
More file actions
140 lines (119 loc) · 5.33 KB
/
Copy pathMainWindow.xaml.vb
File metadata and controls
140 lines (119 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#Region "Copyright"
' Copyright © 2026, TeamDev. All rights reserved.
'
' Redistribution and use in source and/or binary forms, with or without
' modification, must retain the above copyright notice and the following
' disclaimer.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
' "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
' LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
' A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
' OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
' LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
' DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
' THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
' OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#End Region
Imports System.Runtime.InteropServices.ComTypes
Imports System.Text
Imports DotNetBrowser.Browser
Imports DotNetBrowser.Engine
Imports DotNetBrowser.Handlers
Imports DotNetBrowser.Input.DragAndDrop.Events
Imports DotNetBrowser.Input.DragAndDrop.Handlers
Imports DotNetBrowser.Net
''' <summary>
''' This example demonstrates how to intercept drag and drop events
''' and extract data from them.
''' </summary>
Partial Public Class MainWindow
Inherits Window
Private ReadOnly browser As IBrowser
Private ReadOnly engine As IEngine
Public Sub New()
Dim engineBuilder = New EngineOptions.Builder With {
.RenderingMode = RenderingMode.HardwareAccelerated,
.SandboxDisabled = True
}
engineBuilder.ChromiumSwitches.Add("--enable-com-in-drag-drop")
engine = EngineFactory.Create(engineBuilder.Build())
browser = engine.CreateBrowser()
' #docfragment "DragAndDrop.Configuration"
browser.DragAndDrop.EnterDragHandler =
New Handler(Of EnterDragParameters)(AddressOf OnDragEnter)
browser.DragAndDrop.DropHandler = New Handler(Of DropParameters)(AddressOf OnDrop)
' #enddocfragment "DragAndDrop.Configuration"
InitializeComponent()
browserView.InitializeFrom(browser)
browser.Navigation.LoadUrl("teamdev.com")
End Sub
Private Sub ExtractData(eventName As String, dataObject As Windows.IDataObject)
If dataObject Is Nothing Then
Debug.WriteLine("IDataObject is null")
Return
End If
Dim sb As New StringBuilder("=====================================================")
sb.AppendLine($"{vbLf}Event name:{eventName}")
sb.AppendLine($"{vbLf}IDataObject:{dataObject}")
sb.AppendLine("=====================================================")
For Each format As String In dataObject.GetFormats()
sb.AppendLine($"Format:{format}")
Try
Dim data As Object = dataObject.GetData(format)
sb.AppendLine(
$"Type:{(If(data Is Nothing, "[null]", data.GetType().ToString()))}")
sb.AppendLine($"Data:{data}")
Dim strings = TryCast(data, IEnumerable(Of String))
If strings IsNot Nothing Then
For Each s As String In strings
sb.AppendLine($"{vbTab}Value: {s}")
Next s
End If
Catch ex As Exception
sb.AppendLine($"Exception thrown: {ex.Message}")
End Try
sb.AppendLine("=====================================================")
Next format
Dim message As String = sb.ToString()
Dispatcher.BeginInvoke(CType(Sub()
Output.Text = message
End Sub,
Action))
Debug.WriteLine(message)
End Sub
Private Sub LogData(dropData As IDropData, evtName As String)
Debug.WriteLine($"{evtName}:DropData is null? {dropData Is Nothing}")
If dropData IsNot Nothing Then
For Each file As IFileValue In dropData.Files
Debug.WriteLine($"{evtName}:File = {file?.FileName}")
Next file
End If
End Sub
Private Sub MainWindow_OnClosed(sender As Object, e As EventArgs)
browser?.Dispose()
engine?.Dispose()
End Sub
' #docfragment "DragAndDrop.Implementation"
Private Sub OnDragEnter(arg As EnterDragParameters)
LogData(arg.Event.DropData, NameOf(OnDragEnter))
Debug.WriteLine($"Data is null? {(arg.Event.DataObject Is Nothing)}")
Dim dataObject As IDataObject = arg.Event.DataObject
If dataObject IsNot Nothing Then
' Process data in IDataObject.
ExtractData(NameOf(OnDragEnter), New DataObject(dataObject))
End If
End Sub
Private Sub OnDrop(arg As DropParameters)
LogData(arg.Event.DropData, NameOf(OnDrop))
Debug.WriteLine($"Data is null? {(arg.Event.DataObject Is Nothing)}")
Dim dataObject As IDataObject = arg.Event.DataObject
If dataObject IsNot Nothing Then
' Process data in IDataObject.
ExtractData(NameOf(OnDrop), New DataObject(dataObject))
End If
End Sub
' #enddocfragment "DragAndDrop.Implementation"
End Class