如何:修改线条或线段末端的线帽

更新:2007 年 11 月

此示例演示如何在开放式 Shape 元素的起点和终点修改形状。若要在开放式 Shape 的起点更改线帽,请使用其 StrokeStartLineCap 属性。若要在开放式 Shape 的终点更改线帽,请使用其 StrokeEndLineCap 属性。若要查看可用的线帽,请参见 PenLineCap 枚举。

说明:

此属性只影响开放式形状,如 LinePolyline 或开放式 Path 元素。

下面的示例绘制了四个 Polyline 元素并在每个元素的终点处使用不同的一组形状。

示例

<TextBlock Grid.Column="3" Grid.Row="0" Grid.ColumnSpan="2">
  <Bold>Line Caps</Bold>
</TextBlock>
<TextBlock Grid.Column="3" Grid.Row="1">Flat</TextBlock>
<Polyline
  Points="50,50 75,30 100,100 130,40"
  Stroke="Red"
  StrokeThickness="20"
  StrokeStartLineCap="Flat"
  StrokeEndLineCap="Flat"
  Grid.Row="1" Grid.Column="4"/>

<TextBlock Grid.Column="3" Grid.Row="2">Square</TextBlock>
<Polyline
  Points="50,50 75,30 100,100 130,40"
  Stroke="Red"
  StrokeThickness="20"
  StrokeStartLineCap="Square"
  StrokeEndLineCap="Square"    
  Grid.Row="2" Grid.Column="4"/>

<TextBlock Grid.Column="3" Grid.Row="3">Round</TextBlock>
<Polyline
  Points="50,50 75,30 100,100 130,40"
  Stroke="Red"
  StrokeThickness="20"
  StrokeStartLineCap="Round"
  StrokeEndLineCap="Round"  
  Grid.Row="3" Grid.Column="4"/>

<TextBlock Grid.Column="3" Grid.Row="4">Triangle</TextBlock>
<Polyline
  Points="50,50 75,30 100,100 130,40"
  Stroke="Red"
  StrokeThickness="20"
  StrokeStartLineCap="Triangle"
  StrokeEndLineCap="Triangle"     
  Grid.Row="4" Grid.Column="4"/>

此示例摘自一个更大的示例;有关完整的示例,请参见形状元素示例

请参见

参考

Polyline

PenLineCap