闽公网安备 35020302035485号
3.StrokeThickness,主要用于设置形状外边框的宽度,为double类型。
// 增加一个直线形状 var line = new Line(); //设置起始坐标 line.X1 = 1; line.Y1 = 1; //设置结束坐标 line.X2 = 50; line.Y2 = 50; line.HorizontalAlignment = HorizontalAlignment.Left; line.VerticalAlignment = VerticalAlignment.Center; //设置边框线绘制方式和宽度 line.Stroke = System.Windows.Media.Brushes.LightSteelBlue; line.StrokeThickness = 2; myGrid.Children.Add(line);上述代码在XAML中实现,如下所示:
<Line
X1="1" Y1="1"
X2="50" Y2="50"
Stroke="LightSteelBlue"
StrokeThickness="2"
HorizontalAlignment="Left"
VerticalAlignment="Center">
</Line>
尽管Line也有Fill属性,但是一般不会使用,因为Line没有闭合空间,设置了也不会有效果。
// 创建一个椭圆 Ellipse ellipse = new Ellipse(); // 创建一个画笔 SolidColorBrush brush = new SolidColorBrush(); brush.Color = Color.FromArgb(255, 255, 255, 0); ellipse.Fill = brush;//用画笔作为椭圆的填充方式 ellipse.StrokeThickness = 2; ellipse.Stroke = Brushes.Black; // 堆代码 duidaima.com //设置椭圆的大小 ellipse.Width = 200; ellipse.Height = 100;上述代码在XAML中实现,如下所示:
<Ellipse
Fill="#FFFFFF00"
Height="100"
Width="200"
StrokeThickness="2"
Stroke="Black"/>
下图显示了一个呈现的 Ellipse 示例。
<Canvas Width="120" Height="200" >
<!-- 宽100高50,蓝色填充的矩形 -->
<Rectangle
Width="100" Height="50"
Fill="Blue"
Canvas.Left="10"
Canvas.Top="25" />
<!-- 宽100高50,蓝色填充,黑边框,半径为20的圆角的矩形 -->
<Rectangle
Width="100" Height="50"
Fill="Blue"
Stroke="Black" StrokeThickness="4"
RadiusX="20" RadiusY="20"
Canvas.Left="10"
Canvas.Top="100"/>
</Canvas>
非闭合多边形(Ployline)<Canvas Height="400" Width="400">
<Polyline
Points="10,110 60,10 110,110"
Stroke="Black"
StrokeThickness="4" />
<Polyline
Points="10,110 110,110 110,10"
Stroke="Black"
StrokeThickness="4"
Canvas.Left="150" />
</Canvas>
下图显示了一个Ployline的示例:
<Canvas Height="300" Width="300">
<!-- 蓝色三角形 -->
<Polygon Points="10,110 60,10 110,110"
Fill="Blue" />
<!-- 黑边框的蓝色三角形 -->
<Polygon Points="10,110 60,10 110,110"
Fill="Blue"
Stroke="Black" StrokeThickness="4"
Canvas.Top="150" />
<!-- 蓝色填充的三角形 -->
<Polygon Points="10,110 110,110 110,10"
Fill="Blue"
Canvas.Left="150" />
<!-- 黑边框无填充的三角形-->
<Polygon Points="10,110 110,110 110,10"
Stroke="Black" StrokeThickness="4"
Canvas.Left="150" Canvas.Top="150" />
</Canvas>
下图显示了一个Ploygon示例:
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="10,100">
<PathFigure.Segments>
<PathSegmentCollection>
<QuadraticBezierSegment Point1="200,200" Point2="300,100" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
上述代码中,Figures作为PathGeometry的默认属性,Segments作为PathFigure的默认属性,可以省略,简化后的代码如下所示:<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathFigureCollection>
<PathFigure StartPoint="10,100">
<PathSegmentCollection>
<QuadraticBezierSegment Point1="200,200" Point2="300,100" />
</PathSegmentCollection>
</PathFigure>
</PathFigureCollection>
</PathGeometry>
</Path.Data>
</Path>
下图显示了呈现的形状。
<Path Stroke="DarkGoldenRod" StrokeThickness="3"
Data="M 100,200 C 100,25 400,350 400,175 H 280" />
生成的形状如下所示:
<Polygon
Points="0,0 0,1 1,1"
Fill="Blue"
Width="100"
Height="100"
Stretch="Fill"
Stroke="Black"
StrokeThickness="2" />
在上述示例中,使用了 Polygon 来绘制从 (0,0) 到 (0,1) 再到 (1,1) 的一个很小的三角形。Polygon 对象的 Width 和 Height 设置为 100,其拉伸属性设置为 Fill。因此,Polygon 对象的内容(三角形)被拉伸以填充更大的空间。