我需要建立一個自定義WPF控件像這樣 自定義邊框的WPF標籤
正如我在WPF是新的,我用下面的代碼(對不起,VB.NET)
Public Class TextPlaceholder
Inherits System.Windows.Controls.Label
Const CustomBorderWidth As Integer = 2
Public Sub New()
MyBase.New()
Me.BorderBrush = SystemColors.ActiveBorderBrush
End Sub
Protected Overrides Sub OnRender(drawingContext As System.Windows.Media.DrawingContext)
MyBase.OnRender(drawingContext)
Dim pointTopLeft As New Point(-1, -1)
Dim pointTopRight As New Point(Me.ActualWidth, -1)
Dim pointBottomLeft As New Point(-1, Me.ActualHeight)
Dim pointBottomRight As New Point(Me.ActualWidth, Me.ActualHeight)
Dim myPen As New Pen(Me.BorderBrush, CustomBorderWidth)
drawingContext.DrawLine(myPen, pointTopLeft, New Point(pointTopLeft.X + 5, pointTopLeft.Y))
drawingContext.DrawLine(myPen, pointTopLeft, New Point(pointTopLeft.X, pointTopLeft.Y + 5))
drawingContext.DrawLine(myPen, pointTopRight, New Point(pointTopRight.X - 5, pointTopRight.Y))
drawingContext.DrawLine(myPen, pointTopRight, New Point(pointTopRight.X, pointTopRight.Y + 5))
drawingContext.DrawLine(myPen, pointBottomLeft, New Point(pointBottomLeft.X + 5, pointBottomLeft.Y))
drawingContext.DrawLine(myPen, pointBottomLeft, New Point(pointBottomLeft.X, pointBottomLeft.Y - 5))
drawingContext.DrawLine(myPen, pointBottomRight, New Point(pointBottomRight.X - 5, pointBottomRight.Y))
drawingContext.DrawLine(myPen, pointBottomRight, New Point(pointBottomRight.X, pointBottomRight.Y - 5))
End Sub
End Class
現在
1)是否做到這一點的最好辦法,考慮到我將繼承控制和需要在繼承的控制
2)相同的邊框是好到指定博爾的默認值derBrush(不透明),像我一樣?
3)爲什麼我的角落移動像素(不是很正確的鏈接)?
盧卡斯,謝謝你的回答。 a)我不知道如何設置邊界,但角落可見; b) - ; c)據我所知,LineJoin用於poligonal線,但我畫了8條獨立線...... * – serhio 2012-03-08 08:43:39
沒問題,我希望我的回答對你有幫助。我已更新它包含aswers評論。 – 2012-03-08 20:03:05