-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordOverlay.vb
56 lines (55 loc) · 2.13 KB
/
WordOverlay.vb
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
Imports Windows.Media.Ocr
Public Class WordOverlay
Implements INotifyPropertyChanged
Private Word As OcrWord
Private WordBoundingRect As Rect
Public ReadOnly Property WordPosition As Thickness
Get
Return New Thickness(WordBoundingRect.Left, WordBoundingRect.Top, 0, 0)
End Get
End Property
Public ReadOnly Property WordWidth As Double
Get
Return WordBoundingRect.Width
End Get
End Property
Public ReadOnly Property WordHeight As Double
Get
Return WordBoundingRect.Height
End Get
End Property
Public Event PropertyChanged As PropertyChangedEventHandler
Private Event INotifyPropertyChanged_PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub New(OW As OcrWord)
Word = OW
UpdateProps(Word.BoundingRect)
End Sub
Public Sub Transform(scale As ScaleTransform)
UpdateProps(scale.TransformBounds(Word.BoundingRect))
End Sub
Public Function CreateBorder(style As Style, Optional child As UIElement = Nothing) As Border
Dim overlay = New Border() With {
.Child = child,
.Style = style
}
overlay.SetBinding(FrameworkElement.MarginProperty, CreateBinding("WordPosition"))
overlay.SetBinding(FrameworkElement.WidthProperty, CreateBinding("WordWidth"))
overlay.SetBinding(FrameworkElement.HeightProperty, CreateBinding("WordHeight"))
Return overlay
End Function
Private Function CreateBinding(propertyName As String) As Binding
Return New Binding() With {
.Path = New PropertyPath(propertyName),
.Source = Me
}
End Function
Private Sub UpdateProps(wordBoundingBox As Rect)
WordBoundingRect = wordBoundingBox
OnPropertyChanged("WordPosition")
OnPropertyChanged("WordWidth")
OnPropertyChanged("WordHeight")
End Sub
Protected Sub OnPropertyChanged(PropertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
End Sub
End Class