Windows Phone開發(fā)(33):路徑之其它Geometry
上一節(jié)中,我們把最復(fù)雜的PathGeometry給干了,生剩下幾個(gè)家伙就好辦事了。一起來見見他們的真面目吧。
一、LineGeometry
這個(gè)幾何圖形就很簡(jiǎn)單了,一條線段,兩個(gè)點(diǎn)——StartPoint And EndPoint。
一起來看看下面的例子。
- <Path Grid.Column="0" Grid.Row="0">
- <Path.Data>
- <LineGeometry StartPoint="20,5" EndPoint="200,320"/>
- </Path.Data>
- </Path>
運(yùn)行之后你會(huì)看到以下情景:
二、RectangleGeometry
它呈現(xiàn)一人矩形的幾何圖形,Rect指示其中矩形的位置大小,在XAML中可以用4個(gè)數(shù)值表示,即X、Y、Width、Height;別外,RadiusX和RadiusY表示圓角在X軸和Y軸上的半徑。看下面的例子。
- <Path Grid.Column="1" Grid.Row="0">
- <Path.Data>
- <RectangleGeometry Rect="12,6,125,90" RadiusX="24" RadiusY="30"/>
- </Path.Data>
- </Path>
運(yùn)行效果如下圖所示。
三、EllipseGeometry
表示一個(gè)橢圓的幾何圖形,Center屬性為橢圓的中心點(diǎn)的坐標(biāo),RadiusX和RadiusY分別為X軸方向上和Y軸方向上的半徑長(zhǎng)度??蠢?。
- <Path Grid.Column="0" Grid.Row="1">
- <Path.Data>
- <EllipseGeometry Center="100,180" RadiusX="55" RadiusY="120"/>
- </Path.Data>
- </Path>
運(yùn)行效果如下:
四、GeometryGroup
嚴(yán)格上說,它不屬性一種幾何圖形,但它很有用,因?yàn)樗梢酝瑫r(shí)包含N個(gè)幾何圖形,如下面例子所示。
- <Path Grid.Column="1" Grid.Row="1">
- <Path.Data>
- <GeometryGroup>
- <LineGeometry StartPoint="32,185" EndPoint="180,230"/>
- <RectangleGeometry Rect="35,85,136,96" RadiusX="25" RadiusY="5"/>
- <EllipseGeometry Center="112,130" RadiusX="45" RadiusY="36"/>
- </GeometryGroup>
- </Path.Data>
- </Path>
運(yùn)行效是如下所示:
下面是本節(jié)示例的完整XAML代碼。
- <phone:PhoneApplicationPage
- x:Class="Sample.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
- xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{StaticResource PhoneForegroundBrush}"
- SupportedOrientations="Portrait" Orientation="Portrait"
- shell:SystemTray.IsVisible="True">
- <phone:PhoneApplicationPage.Resources>
- <Style TargetType="Path">
- <Setter Property="HorizontalAlignment" Value="Stretch"/>
- <Setter Property="VerticalAlignment" Value="Stretch"/>
- <Setter Property="Margin" Value="20"/>
- <Setter Property="Stroke" Value="Blue"/>
- <Setter Property="StrokeThickness" Value="8"/>
- </Style>
- </phone:PhoneApplicationPage.Resources>
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="*"/>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="*"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <Path Grid.Column="0" Grid.Row="0">
- <Path.Data>
- <LineGeometry StartPoint="20,5" EndPoint="200,320"/>
- </Path.Data>
- </Path>
- <Path Grid.Column="1" Grid.Row="0">
- <Path.Data>
- <RectangleGeometry Rect="12,6,125,90" RadiusX="24" RadiusY="30"/>
- </Path.Data>
- </Path>
- <Path Grid.Column="0" Grid.Row="1">
- <Path.Data>
- <EllipseGeometry Center="100,180" RadiusX="55" RadiusY="120"/>
- </Path.Data>
- </Path>
- <Path Grid.Column="1" Grid.Row="1">
- <Path.Data>
- <GeometryGroup>
- <LineGeometry StartPoint="32,185" EndPoint="180,230"/>
- <RectangleGeometry Rect="35,85,136,96" RadiusX="25" RadiusY="5"/>
- <EllipseGeometry Center="112,130" RadiusX="45" RadiusY="36"/>
- </GeometryGroup>
- </Path.Data>
- </Path>
- </Grid>
- </phone:PhoneApplicationPage>