2012-04-20 117 views

回答

0

你將不得不在兩個相同的點之間畫兩條線,上下兩邊用較粗的筆,上邊用較薄的筆。

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)); 
+0

Thanks this shoudl wo rk :) – 2012-04-20 17:04:54