0
我試圖在WPF中繪製很多類似的線條,如this問題所示,但不同之處在於我需要將它繪製在DrawingVisual對象的DrawingContext上。如何做呢?在DrawingFrame上繪製線條與外線
我試圖在WPF中繪製很多類似的線條,如this問題所示,但不同之處在於我需要將它繪製在DrawingVisual對象的DrawingContext上。如何做呢?在DrawingFrame上繪製線條與外線
你將不得不在兩個相同的點之間畫兩條線,上下兩邊用較粗的筆,上邊用較薄的筆。
Pen background = new Pen(Brushes.Black, 5);
Pen foreground = new Pen(Brushes.White, 3);
drawingContext.DrawLine(background, new Point(100, 100), new Point(200, 200));
drawingContext.DrawLine(foreground, new Point(100, 100), new Point(200, 200));
此線看很多更好,當你還定義了筆線帽:
Pen background = new Pen
{
Brush = Brushes.Black,
Thickness = 5,
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round
};
Pen foreground = new Pen
{
Brush = Brushes.White,
Thickness = 3,
StartLineCap = PenLineCap.Round,
EndLineCap = PenLineCap.Round
};
有了這樣
public static class DrawingContextExtensions
{
public static void DrawLine(this DrawingContext drawingContext,
Pen background, Pen foreground, Point start, Point end)
{
drawingContext.DrawLine(background, start, end);
drawingContext.DrawLine(foreground, start, end);
}
}
擴展方法,你可以做圖中的一個呼叫:
drawingContext.DrawLine(background, foreground, new Point(100, 100), new Point(200, 200));
Thanks this shoudl wo rk :) – 2012-04-20 17:04:54