<a href="http://webabcd.blog.51cto.com/1787395/342790" target="_blank">[索引頁]</a>
<a href="http://down.51cto.com/data/100302">[源碼下載下傳]</a>
穩紮穩打Silverlight(7) - 2.0圖形之Ellipse, Line, Path, Polygon, Polyline, Rectangle
介紹
Silverlight 2.0 圖形:
Ellipse - 橢圓
Line - 線
Path - 一系列互相連接配接的直線和曲線
Polygon - 多邊形,閉合圖形,起點與終點自動相連
Polyline - 非閉合圖形,一串連接配接起來的線,起點與終點不會自動相連
Rectangle - 矩形
線上DEMO
<a href="http://webabcd.blog.51cto.com/1787395/342779">http://webabcd.blog.51cto.com/1787395/342779</a>
示例
1、Ellipse.xaml
<UserControl x:Class="Silverlight20.Shape.Ellipse"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">
<!--橢圓-->
<!--
Width - 橢圓的寬
Height - 橢圓的高
Stroke - 邊框
StrokeThickness - 邊框尺寸
Fill - 填充
-->
<Ellipse Stroke="Red" Fill="Yellow" StrokeThickness="6" Width="100" Height="50"></Ellipse>
</StackPanel>
</UserControl>
2、Line.xaml
<UserControl x:Class="Silverlight20.Shape.Line"
<!--線-->
X1 - 起點的 X 坐标
Y1 - 起點的 Y 坐标
X2 - 終點的 X 坐标
Y2 - 終點的 Y 坐标
注:
Line無填充,也就是Line的Fill屬性無效
坐标以左上角為原點,原點右側/下側為正方向
<Line X1="0" Y1="100" X2="200" Y2="300" Stroke="Black" StrokeThickness="6" />
3、Path.xaml
<UserControl x:Class="Silverlight20.Shape.Path"
<!--繪制一系列互相連接配接的直線和曲線-->
Path.Data - 要繪制的形狀的 Geometry
<Path Fill="Yellow" Stroke="Red" StrokeThickness="6">
<Path.Data>
<!--橢圓-->
<!--
Center - 原點坐标
RadiusX - X軸半徑
RadiusY - Y軸半徑
-->
<EllipseGeometry Center="50,25" RadiusX="50" RadiusY="25" />
</Path.Data>
</Path>
<!--矩形-->
Rect - 矩形的點坐标,分别為:左側線的X軸坐标,上側線的Y軸坐标,矩形寬,矩形高
<RectangleGeometry Rect="100,0,100,50" />
<Path Stroke="Red" StrokeThickness="6" >
<!--線-->
StartPoint - 起點坐标
EndPoint - 終點坐标
<LineGeometry StartPoint="200,0" EndPoint="300,100" />
<Path Stroke="Red" StrokeThickness="6">
<!--一個可能由弧、曲線、橢圓、直線和矩形組成的複雜圖形-->
<PathGeometry>
<PathGeometry.Figures>
<!--
StartPoint - 圖形起點坐标
-->
<PathFigure StartPoint="300,0">
<!--
PathFigure.Segments - 待畫線的類型
-->
<PathFigure.Segments>
<PathSegmentCollection>
<!--
LineSegment - 單一線段
PolyLineSegment - 線段集合
ArcSegment - 弧(橢圓的一部分)
BezierSegment - 兩點之間的一條三次貝塞爾曲線
QuadraticBezierSegment - 兩點之間的一條二次貝塞爾曲線
PolyBezierSegment - 一條或多條三次貝塞爾曲線
PolyQuadraticBezierSegment - 一條或多條二次貝塞爾曲線
-->
Size - 弧的X軸和Y軸半徑
Point - 該Segment的終點坐标,下一個Segment的起點坐标
-->
<ArcSegment Size="100,50" Point="400,100" />
<LineSegment Point="500,200" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
<!--一個或多個Geometry-->
FillRule - 填充規則 [System.Windows.Media.FillRule枚舉]
EvenOdd 和 Nonzero,詳見MSDN
<GeometryGroup FillRule="EvenOdd">
<LineGeometry StartPoint="200,0" EndPoint="300,100" />
<EllipseGeometry Center="250,50" RadiusX="50" RadiusY="50" />
<RectangleGeometry Rect="200, 0, 100, 100" />
</GeometryGroup>
4、Polygon.xaml
<UserControl x:Class="Silverlight20.Shape.Polygon"
<!--多邊形,閉合圖形,起點與終點自動相連-->
Points - 構造路徑所使用的點
空格分隔點坐标,逗号分隔X軸和Y軸坐标
<Polygon Points="0,0 100,0 300,100 200,100 100,200" Stroke="Red" StrokeThickness="6" Fill="Yellow" />
5、Polyline.xaml
<UserControl x:Class="Silverlight20.Shape.Polyline"
<!--非閉合圖形,一串連接配接起來的線,起點與終點不會自動相連-->
<Polyline Points="0,0 100,0 300,100 200,100 100,200" Stroke="Red" StrokeThickness="6" Fill="Yellow" />
6、Rectangle.xaml
<UserControl x:Class="Silverlight20.Shape.Rectangle"
<!--矩形-->
RadiusX - 邊角圓弧的X軸半徑
RadiusY - 邊角圓弧的Y軸半徑
<Rectangle Width="200" Height="120" Stroke="Black" StrokeThickness="6" RadiusX="10" RadiusY="30" />
OK
<a href="http://down.51cto.com/data/100302" target="_blank">[源碼下載下傳</a>
本文轉自webabcd 51CTO部落格,原文連結:http://blog.51cto.com/webabcd/342831,如需轉載請自行聯系原作者