흠.
Imports System.Windows
Imports System.Windows.Documents
Imports System.Windows.Media
Public Class Annotation
Inherits Adorner
Private _fill As Brush
Private _pen As Pen
Private _text As FormattedText
Private _annotationText as String
Public Sub New(ByVal adornedElement As UIElement, ByVal annotationText as String)
MyBase.New(adornedElement)
_annotationText = annotationText
_fill = New SolidColorBrush(Color.FromArgb(&H33, &HB0, &HC4, &HDE))
_fill.Freeze()
_pen = New Pen(Brushes.LightSteelBlue, 3.0)
_pen.Freeze()
_text = New FormattedText(_annotationText, Globalization.CultureInfo.InvariantCulture, FlowDirection.LeftToRight, New Typeface("Verdana"), 11.0, Brushes.Black)
Me.IsHitTestVisible = False
End Sub
Protected Overrides Sub OnRender(ByVal drawingContext As DrawingContext)
MyBase.OnRender(drawingContext)
Dim adornedRect As New Rect(MyBase.AdornedElement.RenderSize)
drawingContext.DrawRectangle(_fill, _pen, adornedRect)
drawingContext.DrawText(_text, New Point(0,0))
End Sub
End Class
을 그리고 당신은하여 사용하는 것이 : 나는 아마 adorner 함께 할 것입니다 나는 위치와 주석의 실제 모양을 조정할 수 떠나
Private Sub AddAnnotation(ByVal uie As UIElement, ByVal annotationText as String)
Dim annotation = New Annotation(uie)
Dim adornerLayer = AdornerLayer.GetAdornerLayer(uie, annotationText)
adornerLayer.Add(annotation)
End Sub
,하지만 당신은 얻을 아이디어. 이는 UIElement (사용자 지정 컨트롤 포함)에서 작동합니다.
이것은 Adorners와 함께했던 다른 작업을 기반으로 한 커프스 답답함이었습니다. 위의 코드는 컴파일 될 수도 있고 컴파일되지 않을 수도 있습니다. 주석을 편집하는 방법은 제공하지 않았지만 "Me.IsHitTestVisible = False"라인을 제거하고 adorner에서 MouseUp 이벤트를 처리하면 쉽게 주석을 편집 할 수 있습니다.
DocumentViewer와 같은 주석을 컨트롤에서 사용할 수 있습니다. 해당 설명과 코드 스 니펫을 주셔서 감사합니다.이 코드를 실행하고 사용권을 얻을 수 있는지 확인하겠습니다. – Vin
UIElement에서 작동하는 무언가가 필요하기 때문에 기존의 Annotations를 사용하지 않아도 될 것입니다. 일반 UI 개발에서 다루는 거의 독점적으로 UIElement와 작동하는 무언가가 필요하기 때문입니다. 제 3 자 프로젝트가 있을지 모르지만 저는 그것을 모르고 있습니다. –