我需要建立一个自定义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